Is JSON array parsable? (Stream parser) - javascript

I have a YQL query that extracts data from a page and returns it to my script as JSON. The JSON is huge, and as such, here's my question:
Is JSON array parsable? So that I can iterate over the entire JSON structure?

JSON per definition is parsable - it is JAVASCRIPT. The question is moe how much code that neeeds, which may depend on the specific JSON array (how little can you get away with).
If JSON would not be parsable in principle, it would be totally worthless, you know.

Related

Is there any performance overhead with sending JSON objects instead of stringified JSON through node js APIs?

While writing node js APIs, we can send plain JSON objects as params (body params), I think there must be some additional overhead for the formatting instead what if I stringify the JSON while sending to API and will parse back to original JSON while processing it.
Can you guys please suggest if this approach gives any performance advantage?
JSON is "JavaScript Object Notation" — i.e. some string format to serialize Object, to save, transfer and restore Object to/via/from a string. JSON.stringify() does not mean you stringify JSON: JSON here is not an object of stringifying, but a namespace like in Math.sqrt(). You cannot transfer Object as is via HTTP or IPC: for this purpose, you have a text serialization format, i.e. JSON.

GWT JavaScriptObject: get original json string?

I have been working with JSONP on my GWT application. When my server sends a json string, I can get it in the form of a JavaScriptObject on the client side.
My problem is my json has complicated structures: using maps, nests with a lot of different keys. That is a big pain to extract data (I may have to write few hundred functions for all keys to extract data one by one and some complicated codes to fill maps).
I am considering few solutions:
Encode and send whole json strings as normal strings to client (as a value of a simple json string). Just worry my encoded strings may be few time longer than the original ones and may easily exceed the limit of 2k long
Convert back a JavaScriptObject into a pure string (similar to one I sent from the server)
After having a pure string I will parse it using some json parsers / methods to the structures I feel convenient.
My questions:
1) How to convert back a JavaScriptObject object into a pure / original json string?
2) Any idea about solutions?
Many thanks
1) Convert JavaScriptObject to JSON: JsonUtils.stringify(yourJSO)
Convert JSON to JavaScriptObject: JsonUtils.safeEval(jsonString);
2) Did you think about using AutoBeans?? Check out the GWT page

Do empty arrays in JSON hurt performance when parsing the JSON dataset?

I have a rather large JSON data set that I am parsing through using DoT.js to populate a template for display. I see that there are over 3400 empty arrays for a portion of the JSON that I am not even using to populate the template. Here is the piece of unused JSON.
,"COMMENTS":[]
I am parsing through it at an earlier point in my code to convert the keys to in the entire JSON data set to lowercase.
,"comments":[]
Does having a empty array like this impact performance negatively?
Yes, it has an impact on performances. First, data transfer will take a little longer, but also JSON parsing will be slower.
http://jsperf.com/json-empty-arrays-perf

JSON to String on client side for ASP.NET Script Service?

From this site, I've learned that ASP.NET script services accepting JSON actually require them to be serialized JSON strings (see: "JSON, objects, and strings: oh my!" section of the link). Is there a quick and easy way to serialize them for ASP.NET AJAX consumption on the client side instead of trying to manually convert a bunch of existing objects to JSON-looking strings?
Thanks in advance!
You can use JSON.stringify() to serialize client-side objects for consumption in ASP.NET's Script Services.
Using that approach, you can map client-side objects to server-side objects very easily. ASP.NET will automatically handle converting the JSON to objects (or even collections of objects) for you.
The article writer is confusing Javascript objects with JSON strings. There is no such thing as a "JSON object".
Naturally if you try to send an object to a web service, it has to be serialised, as the request data can only contain text, not objects. The standard way of serialising data to be posted is URL encoding it, so that is what jQuery does.
There is no JSON serialisation built into Javascript or jQuery. You would have to do the serialising yourself or find a library that does it. Here are some options: Serializing to JSON in jQuery
Also, the data sent in the example is not valid JSON. It looks like this:
"{'fname':'dave', 'lname':'ward'}"
To be valid JSON it should look like this:
'{"fname":"dave", "lname":"ward"}'

JSON or XML or other data format with jQuery ajax()?

For a data send, where the return data contains potential updates for hundreds of elements on a page, is XML or JSON or another data format better, for usage with jQuery's various parsing formats (invoked via ajax() success)?
Check out this article, it outlines various pros/cons of XML, JSON and HTML when processing AJAX requests.
Personally I'd pick JSON as it uses less bandwidth & is easier to parse and use.
It sounds like a lot of data being returned so json. It's lighter and more compact. Plus it has native use instead of having to parse the xml and traverse it afterwards.
In javascript it is better to go with JSON because it is easier to code and less data to load from the server, unlike XML you have to write a code to parse the elements and fetch the values to your object and for every change in data tags or elements in XML you will need to modify your javascript code which means more coding and testing, unlike JSON all what you need is eval() and you are ready to go.

Categories

Resources