473,856 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JSON Question

It is my understanding that you cannot pass a double quote (") or back slash
(\) character as part of a value string.

I've got a senario where I'm extracting database information that may
contain double quote character(s). Are there any tricks out there that would
allow me to extract the database information, double quote character(s)
included?

Thanks in advance, Ian Renfrew
Jul 23 '05 #1
2 8207
Ian Renfrew wrote:
It is my understanding that you cannot pass a double quote
(") or back slash (\) character as part of a value string.
?
I've got a senario where I'm extracting database information
that may contain double quote character(s). Are there any tricks
out there that would allow me to extract the database information,
double quote character(s) included?


It is normal practice to pass data of unknown content through a function
(of some sort) that renders it 'safe' before dynamically inserting it
into contexts where particular characters may be problematic. For
insertion into a javascript string literal, in a CDATA context,
transforming escapes, quotes, apostrophes, tabs, linefeeds, carriage
returns, copyright symbols, etc, into their hexadecimal or Unicode
escape equivalents should be sufficient. E.G.:-

" --> \x22 - or - \u0022

This inevitably expands the size of the data so it is usually best to
only apply the transformation to characters that may be significant in
the output context.

If the data already contains 'escape sequences' of some sort it would be
necessary to normalise it first.

Richard.
Jul 23 '05 #2
Thanks Richard,

Thats done the trick. I was also able to prefix the two characters with the
backslash / escape character, thus \ turns into \\ and " turns into \".

Regards, Ian

"Richard Cornford" <Ri*****@litote s.demon.co.uk> wrote in message
news:d4******** ***********@new s.demon.co.uk.. .
Ian Renfrew wrote:
It is my understanding that you cannot pass a double quote
(") or back slash (\) character as part of a value string.


?
I've got a senario where I'm extracting database information
that may contain double quote character(s). Are there any tricks
out there that would allow me to extract the database information,
double quote character(s) included?


It is normal practice to pass data of unknown content through a function
(of some sort) that renders it 'safe' before dynamically inserting it
into contexts where particular characters may be problematic. For
insertion into a javascript string literal, in a CDATA context,
transforming escapes, quotes, apostrophes, tabs, linefeeds, carriage
returns, copyright symbols, etc, into their hexadecimal or Unicode
escape equivalents should be sufficient. E.G.:-

" --> \x22 - or - \u0022

This inevitably expands the size of the data so it is usually best to
only apply the transformation to characters that may be significant in
the output context.

If the data already contains 'escape sequences' of some sort it would be
necessary to normalise it first.

Richard.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2707
by: G Matthew J | last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm This is more or less in response to Mr Crockford's admonition a few months ago, "fork if you must". Ironically, although in that usenet post he calls what I am suggesting "brittle", his own Javascript JSON parser is not valid JSON, but rather conforms to my proposed variation on JSON!! With an identifier prepended to the front of the JSON block, and function literals as values: see...
10
3006
by: Frank Millman | last post by:
Hi all I am writing a multi-user accounting/business application, which uses sockets to communicate between server and client. The server contains all the business logic. It has no direct knowledge of the client. I have devised a simple message format to exchange information between the two. At first, I used XML as a message format. Then I read the article that recommended not using XML for Python-to-Python, so I changed it to a
3
18142
by: asleepatdesk | last post by:
Hi, I need some help here. When I try to eval() my AJAX returned JSON string, I continually get a javascript error "Expected )". Here's my JSON string: {"recs": }; My js function simply tries to eval() it: var jsonStr = eval('(' + str + ')');
2
2520
by: holtmann | last post by:
Hi, I got a question regarding JSON as datasource- I understand that eval on a JSON String creates the appropriate objects in JS. But I would like to use JSON to supply data to already defined prototpye objects. I try to give an example. I e.g. got: address.prototype = { firstname: null;
19
1999
RMWChaos
by: RMWChaos | last post by:
Previously, I had used independent JSON lists in my code, where the lists were part of separate scripts. Because this method did not support reuse of a script without modification, I decided to consolidate all my JSON lists into one and modify my scripts so that they were more generic and reusable. So far so good. The problem is that my JSON lists used variables for many pieces of code that performed multiple iterations to create several...
4
8879
by: im12345 | last post by:
I have the following question: Im doing a sample application using dojo and json. I have 2 classes: 1. Book class package com.esolaria.dojoex; import org.json.JSONObject; import org.json.JSONException;
2
2025
by: vunet | last post by:
When implementing JSON as a form of data exchange between server and client, what security measures do I need to consider? For example, I have XMLHttpRequest returning JSON text from the server and eval() converts string to the JavaScript object. I heard about problems with "eval" and idea of using "magic cookies" to avoid attacks. Anyway, what should I consider? Thanks.
5
8183
by: Jeff | last post by:
Lets say we have what I would call a "hash": var HASH =new Array(); HASH='first'; HASH='second'; HASH='third'; I'd like to return that as JSON data. Is there a direct way to do that?
6
2836
by: Lasse Reichstein Nielsen | last post by:
Max <adsl@tiscali.itwrites: Not really. It shows that a particularly naïve implementation of a conversion from XML to JSON doesn't work well. What if the conversion of <e> some
9
2229
by: BryanA | last post by:
Is it possible to parse JSON data and then post it to a mysql db with the data in their respective fields?
0
9904
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10773
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9527
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5756
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4170
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3196
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.