473,396 Members | 1,933 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,396 software developers and data experts.

escapes and JSON

hi, this has been a bugger for me.

JSON:

{" + escape('some (annoying) text') + " : "friendly text" }

i want to escape the text inside the escape function but
show the results inside double quotes!

The above line puts everything inside the double quotes and
the escape function is now text.

How is this done??
Dec 4 '07 #1
4 2301
On Dec 5, 4:57 am, pbd22 <dush...@gmail.comwrote:
hi, this has been a bugger for me.

JSON:

{" + escape('some (annoying) text') + " : "friendly text" }
You're quoting the function there.

If you LITERALLY want the double quotes:

{'"' + escape('some (annoying) text') + '"' : "friendly text" }

But this is strange since the "friendly text" is not in literal double
quotes. If instead you want the result of the escape function to have
the same quoting level as the friendly text:

{ escape('some (annoying) text') : "friendly text" }

But it's rarely (never?) a good idea to have special characters in
your key/attribute name.
Dec 4 '07 #2
On Dec 4, 4:48 pm, slebetman <slebet...@gmail.comwrote:
On Dec 5, 4:57 am, pbd22 <dush...@gmail.comwrote:
hi, this has been a bugger for me.
JSON:
{" + escape('some (annoying) text') + " : "friendly text" }

You're quoting the function there.

If you LITERALLY want the double quotes:

{'"' + escape('some (annoying) text') + '"' : "friendly text" }

But this is strange since the "friendly text" is not in literal double
quotes. If instead you want the result of the escape function to have
the same quoting level as the friendly text:

{ escape('some (annoying) text') : "friendly text" }

But it's rarely (never?) a good idea to have special characters in
your key/attribute name.

OK, thanks.

SO, how do handle special case characters in my JSON strings?

I have keys such as "The Last Mermain (1994) - Limited Edition".

I agree with you, escape really messes things up. But, the
special characters are causing all sorts of probs with JSON
syntax.

Please help... deadline.

THanks.
Dec 4 '07 #3
On Dec 4, 12:57 pm, pbd22 <dush...@gmail.comwrote:
hi, this has been a bugger for me.

JSON:

{" + escape('some (annoying) text') + " : "friendly text" }

i want to escape the text inside the escape function but
show the results inside double quotes!

The above line puts everything inside the double quotes and
the escape function is now text.

How is this done??
Have you thought about using a JSON dumper so you don't have to worry
about this stuff?

var obj = {'some (annoying) text':'friendly text'};

FORK.Json.dump(obj)

<URL:http://dev.michaux.ca/svn/fork/trunk...ascripts/fork/
json.js>

<URL:http://forkjavascript.org/json/docs>

Peter
Dec 5 '07 #4
On Dec 5, 2:19 pm, Jeremy J Starcher <r3...@yahoo.spam.me.not.com>
wrote:
On Tue, 04 Dec 2007 14:45:17 -0800, pbd22 wrote:

[snip of some sample code]
OK, thanks.
SO, how do handle special case characters in my JSON strings?
I have keys such as "The Last Mermain (1994) - Limited Edition".
I agree with you, escape really messes things up. But, the
special characters are causing all sorts of probs with JSON
syntax.
Please help... deadline.
THanks.

Chances are, with that key like that, you have a design issue. I can't
see your code, so I'm not 100% certain -- but I strongly suggest you
look things over and go "Why?"

That said, if you are totally sure you want to do this, there might
be a better way to get what you are after. (Even with the best CRC
method there is still a (very small) chance collisions. Reading up
on hash tables and how to handle collisions isn't a bad idea.)
Well, one way of totally avoiding collisions is to simply base64
encode the key. If base64's '+' and '/' characters still give you
trouble then simply convert the key to hex which should handle
anything you care to throw at it. But if you do go the hex route
remember to be consistent and either ALWAYS use uppercase OR ALWAYS
use lowercase since keys are case sensitive.
Dec 6 '07 #5

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...
20
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
2
by: Kevin Newman | last post by:
Hello, I noticed that the JavaScript library for JSON posted on json.org (http://www.json.org/json.js) is modifying Object.prototype (adding a method - toJSONString). I thought this was...
3
by: Adam | last post by:
I'm trying to retrieve some values from a json object, but instead it's giving me the property name. For example: var json = { "glossary": { "title": "example glossary" } }; console.log(json);...
2
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
23
by: dhtmlkitchen | last post by:
JSON We all know what it is. In ECMAScript 4, there's a JSON proposal: Object.prototype.toJSONString String.prototype.parseJSON The current proposal, String.prototype.parseJSON, returns...
9
by: Jon Paal [MSMD] | last post by:
using json like ( {"Records": , "RecordCount":"1" } ) and jquery like: $.ajax({ .... success: function(json, status) {
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
0
by: crocodilu2008 | last post by:
JSON vs. XML JSON and XML are basically used for the same purpose—to represent and interchange data. I'll try to show you why you might want to use JSON rather than XML in an AJAX context by showing...
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:
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
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,...
0
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...
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
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...
0
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,...

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.