473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 8185
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*****@litotes.demon.co.uk> wrote in message
news:d4*******************@news.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
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...
10
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...
3
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...
2
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...
19
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...
4
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...
2
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...
5
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.