All Questions

Tagged with
Filter by
Sorted by
Tagged with
4329votes
8answers
570kviews

Why does Google prepend while(1); to their JSON responses?

Why does Google prepend while(1); to their (private) JSON responses? For example, here's a response while turning a calendar on and off in Google Calendar: while (1); [ ['u', [ ['smsSentFlag', ...
user avatar
  • 40.9k
3012votes
28answers
1.4mviews

pretty-print JSON using JavaScript

How can I display JSON in an easy-to-read (for human readers) format? I'm looking primarily for indentation and whitespace, with perhaps even colors / font-styles / etc.
user avatar
  • 61.7k
2338votes
10answers
557kviews

What is JSONP, and why was it created?

I understand JSON, but not JSONP. Wikipedia's document on JSON is (was) the top search result for JSONP. It says this: JSONP or "JSON with padding" is a JSON extension wherein a prefix is specified ...
user avatar
  • 184k
1734votes
16answers
2.0mviews

Parse JSON in JavaScript? [duplicate]

I want to parse a JSON string in JavaScript. The response is something like var response = '{"result":true,"count":1}'; How can I get the values result and count from this?
user avatar
1717votes
59answers
1.1mviews

Convert form data to JavaScript object with jQuery

How do I convert all elements of my form to a JavaScript object? I'd like to have some way of automatically building a JavaScript object from my form, without having to loop over each element. I do ...
1441votes
27answers
1.4mviews

Safely turning a JSON string into an object

Given a string of JSON data, how can I safely turn that string into a JavaScript object? Obviously I can do this unsafely with something like: var obj = eval("(" + json + ')'); but that leaves me ...
user avatar
1382votes
15answers
1.5mviews

What is the "right" JSON date format?

I've seen so many different standards for the JSON date format: "\"\\/Date(1335205592410)\\/\"" .NET JavaScriptSerializer "\"\\/Date(1335205592410-0500)\\/\"" .NET ...
user avatar
1325votes
27answers
1.7mviews

Convert JS object to JSON string

If I defined an object in JS with: var j={"name":"binchen"}; How can I convert the object to JSON? The output string should be: '{"name":"binchen"}'
user avatar
  • 57.6k
1322votes
74answers
1.4mviews

How to compare arrays in JavaScript?

I'd like to compare two arrays... ideally, efficiently. Nothing fancy, just true if they are identical, and false if not. Not surprisingly, the comparison operator doesn't seem to work. var a1 = [1,2,...
user avatar
1229votes
11answers
912kviews

Serializing to JSON in jQuery [duplicate]

I need to serialize an object to JSON. I'm using jQuery. Is there a "standard" way to do this? My specific situation: I have an array defined as shown below: var countries = new Array(); countries[0]...
user avatar
  • 49.5k
1015votes
31answers
1.0mviews

How to parse JSON using Node.js? [closed]

How should I parse JSON using Node.js? Is there some module which will validate and parse JSON securely?
user avatar
880votes
15answers
417kviews

Ajax request returns 200 OK, but an error event is fired instead of success

I have implemented an Ajax request on my website, and I am calling the endpoint from a webpage. It always returns 200 OK, but jQuery executes the error event. I tried a lot of things, but I could not ...
user avatar
825votes
16answers
1.2mviews

Fetch: POST JSON data

I'm trying to POST a JSON object using fetch. From what I can understand, I need to attach a stringified object to the body of the request, e.g.: fetch("/echo/json/", { headers: { '...
user avatar
  • 22.6k
810votes
29answers
849kviews

How can I print a circular structure in a JSON-like format?

I have a big object I want to convert to JSON and send. However it has circular structure. I want to toss whatever circular references exist and send whatever can be stringified. How do I do that? ...
user avatar
  • 49k
773votes
12answers
654kviews

Using Node.JS, how do I read a JSON file into (server) memory?

Background I am doing some experimentation with Node.js and would like to read a JSON object, either from a text file or a .js file (which is better??) into memory so that I can access that object ...
user avatar
  • 22.2k

15 30 50 per page
1
2 3 4 5
5018