473,322 Members | 1,610 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,322 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 8180
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.