473,379 Members | 1,539 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,379 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 8183
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?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.