Questions tagged [json]

JSON (JavaScript Object Notation) is a serializable data interchange format intended to be machine and human readable. Do not use this tag for native JavaScript objects or JavaScript object literals. Before you ask a question, validate your JSON using a JSON validator such as JSONLint (https://jsonlint.com).

JSON (JavaScript Object Notation) is a serializable data interchange format intended to be machine- and human-readable.

JSON is defined by RFC 7159 which is completely language independent, but it uses conventions familiar to programmers of the C-family of languages, including , , , , , , , and many others. These properties make JSON an ideal data-interchange language to use with RESTful APIs or . It is often used instead of because of its lightweight and compact structure.

Many programming languages provide methods for parsing a JSON-formatted text string into a native object and vice versa. For example, JavaScript in modern browsers and other environments includes the methods JSON.parse() and JSON.stringify().

The JSON format is based on two types of structures:

  • Collection of name/value pairs

    {"name1":"value1", "name2":"value2"}
    
  • An ordered list of values (more commonly referred to as an array)

    ["value1", "value2"]
    

JSON defines six types of values: null, numbers, strings, booleans, arrays and objects. With regard to objects, the order of members is not significant, and the behavior of a JSON parser when duplicate member names are encountered is undefined.

Note that JSON is not the same thing as JavaScript object literals. Rather, JSON is a common format to serialize from and deserialize to objects in most languages. For more information, see There is no such thing as a JSON object in JavaScript.

Shortly after it was created, JSON validation was added following the description set out by Douglas Crockford of json.org in RFC 4627. It has since been expanded to also validate both current competing JSON standards RFC 7159 and ECMA-404.


Advantages

  • JSON is a lightweight data-interchange format (no markup bloat)
  • JSON is language independent.
  • JSON is "self-describing" and easy to understand.
  • JSON can be natively understood by JavaScript parsers, including node.js

JSON libraries


Browser Addons


Useful links


Books


See also

319098 questions
10720
votes
36 answers

What is the correct JSON content type?

I've been messing around with JSON for some time, just pushing it out as text and it hasn't hurt anybody (that I know of), but I'd like to start doing things properly. I have seen so many purported "standards" for the JSON content…
Oli
  • 215,718
  • 61
  • 207
  • 286
8287
votes
56 answers

Can comments be used in JSON?

Can I use comments inside a JSON file? If so, how?
Michael Gundlach
  • 94,522
  • 11
  • 34
  • 39
4244
votes
8 answers

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', 'false'], ['hideInvitations', 'false'], …
Jess
  • 39,842
  • 6
  • 34
  • 51
3275
votes
57 answers

How can I pretty-print JSON in a shell script?

Is there a (Unix) shell script to format JSON in human-readable form? Basically, I want it to transform the following: { "foo": "lorem", "bar": "ipsum" } ... into something like this: { "foo": "lorem", "bar": "ipsum" }
AnC
3230
votes
25 answers

How do I POST JSON data with cURL?

I use Ubuntu and installed cURL on it. I want to test my Spring REST application with cURL. I wrote my POST code at the Java side. However, I want to test it with cURL. I am trying to post a JSON data. Example data is like…
kamaci
  • 65,625
  • 65
  • 210
  • 342
2765
votes
25 answers

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.
Mark
  • 57,724
  • 41
  • 114
  • 149
2256
votes
11 answers

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 as an input argument of the call itself. Huh?…
Cheeso
  • 180,104
  • 92
  • 446
  • 681
2070
votes
41 answers

How do I format a Microsoft JSON date?

I'm taking my first crack at Ajax with jQuery. I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. Basically, I'm getting a string back that looks like…
Mark Struzinski
  • 31,745
  • 33
  • 103
  • 135
1701
votes
16 answers

Parse JSON in JavaScript?

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?
user605334
1681
votes
54 answers

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 not want a string, as returned by…
Yisroel
  • 8,144
  • 4
  • 24
  • 26
1489
votes
9 answers

Why can't Python parse this JSON data?

I have this JSON in a file: { "maps": [ { "id": "blabla", "iscategorical": "0" }, { "id": "blabla", "iscategorical": "0" } ], "masks": [ "id":…
michele
  • 24,748
  • 27
  • 92
  • 146
1399
votes
28 answers

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 vulnerable to the JSON string containing other code,…
Matt Sheppard
  • 111,039
  • 46
  • 105
  • 128
1342
votes
14 answers

How to prettyprint a JSON file?

I have a JSON file that is a mess that I want to prettyprint. What's the easiest way to do this in Python? I know PrettyPrint takes an "object", which I think can be a file, but I don't know how to pass a file in. Just using the filename doesn't…
Colleen
  • 18,089
  • 12
  • 42
  • 70
1302
votes
14 answers

How do I write JSON data to a file?

I have JSON data stored in the variable data. I want to write this to a text file for testing so I don't have to grab the data from the server each time. Currently, I am trying this: obj = open('data.txt', 'wb') obj.write(data) obj.close And I am…
user1530318
  • 19,347
  • 13
  • 31
  • 46
1300
votes
27 answers

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"}'
Bin Chen
  • 54,865
  • 51
  • 136
  • 180
1
2 3
99 100