Questions tagged [json]

JSON (JavaScript Object Notation) is a serializable data interchange format that is a 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 behaviour of a JSON parser when duplicate member names are encountered is undefined.

Note that JSON is not the same thing as JavaScript object literals. Instead, JSON is a standard format to serialize from and deserialize 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 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

357960 questions
11461
votes
39 answers

Which JSON content type do I use?

There are many "standards" for the JSON content type: application/json application/x-javascript text/javascript text/x-javascript text/x-json Which one do I use, and where? I assume security and browser support issues are a factor. Related: What…
Oli
  • 235,628
  • 64
  • 220
  • 299
9409
votes
59 answers

Can comments be used in JSON?

Can I use comments inside a JSON file? If so, how?
Michael Gundlach
  • 106,555
  • 11
  • 37
  • 41
4461
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
  • 42,368
  • 6
  • 37
  • 51
3723
votes
31 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
  • 72,915
  • 69
  • 228
  • 366
3609
votes
62 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
3337
votes
31 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
  • 67,098
  • 47
  • 117
  • 162
2434
votes
10 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
  • 189,189
  • 101
  • 473
  • 713
2153
votes
42 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
  • 32,945
  • 35
  • 107
  • 137
1872
votes
15 answers

How to prettyprint a JSON file?

How do I pretty-print a JSON file in Python?
Colleen
  • 23,899
  • 12
  • 45
  • 75
1758
votes
58 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,164
  • 4
  • 26
  • 26
1754
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
1695
votes
16 answers

How do I write JSON data to a file?

How do I write JSON data stored in the dictionary data to a file? f = open('data.json', 'wb') f.write(data) This gives the error: TypeError: must be string or buffer, not dict
user1530318
  • 25,507
  • 15
  • 37
  • 48
1512
votes
56 answers

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,3]; var a2 = [1,2,3]; console.log(a1==a2); //…
Julian H. Lam
  • 25,501
  • 13
  • 46
  • 73
1505
votes
16 answers

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 DataContractJsonSerializer "2012-04-23T18:25:43.511Z" …
Kamyar Nazeri
  • 25,786
  • 15
  • 50
  • 87
1504
votes
3 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
  • 26,348
  • 30
  • 111
  • 168
1
2 3
99 100