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
763
votes
19 answers

Binary Data in JSON String. Something better than Base64

The JSON format natively doesn't support binary data. The binary data has to be escaped so that it can be placed into a string element (i.e. zero or more Unicode chars in double quotes using backslash escapes) in JSON. An obvious method to escape…
dmeister
  • 34,704
  • 19
  • 73
  • 95
746
votes
20 answers

How to "pretty" format JSON output in Ruby on Rails

I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted. Right now, I call to_json and my JSON is all on one line. At times this can be difficult to see if there is a problem in the JSON output stream. Is there way to…
JP Richardson
  • 38,609
  • 36
  • 119
  • 151
746
votes
22 answers

Finding the max value of an attribute in an array of objects

I'm looking for a really quick, clean and efficient way to get the max "y" value in the following JSON slice: [ { "x": "8/11/2009", "y": 0.026572007 }, { "x": "8/12/2009", "y": 0.025057454 }, { "x": "8/13/2009", …
Rio
  • 14,182
  • 21
  • 67
  • 107
737
votes
12 answers

Ignoring new fields on JSON objects using Jackson

I'm using Jackson JSON library to convert some JSON objects to POJO classes on an android application. The problem is, the JSON objects might change and have new fields added while the application is published, but currently it will break even when…
Hadi Eskandari
  • 25,575
  • 8
  • 51
  • 65
728
votes
30 answers

Can I set an unlimited length for maxJsonLength in web.config?

I am using the autocomplete feature of jQuery. When I try to retrieve the list of more then 17000 records (each won't have more than 10 char length), it's exceeding the length and throws the error: Exception information: Exception type:…
Prasad
  • 58,881
  • 64
  • 151
  • 199
703
votes
17 answers

Error "Cannot use object of type stdClass as array"

I get a strange error using json_decode(). It decodes the data correctly (I saw it using print_r), but when I try to access to information inside the array I get: Fatal error: Cannot use object of type stdClass as array…
Dail
  • 7,039
  • 3
  • 15
  • 3
670
votes
15 answers

Return JSON response from Flask view

I have a function that analyzes a CSV file with Pandas and produces a dict with summary information. I want to return the results as a response from a Flask view. How do I return a JSON response? @app.route("/summary") def summary(): d =…
Code Ninja
  • 6,963
  • 5
  • 16
  • 12
656
votes
20 answers

Preferred method to store PHP arrays (json_encode vs serialize)

I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in my web app but the vast majority of the time I will be using the array…
KyleFarris
  • 17,274
  • 5
  • 40
  • 40
625
votes
29 answers

How do I cast a JSON Object to a TypeScript class?

I read a JSON object from a remote REST server. This JSON object has all the properties of a typescript class (by design). How do I cast that received JSON object to a type var? I don't want to populate a typescript var (ie have a constructor that…
David Thielen
  • 28,723
  • 34
  • 119
  • 193
622
votes
8 answers

Representing null in JSON

What is the preferred method for returning null values in JSON? Is there a different preference for primitives? For example, if my object on the server has an Integer called "myCount" with no value, the most correct JSON for that value would…
pherris
  • 17,195
  • 8
  • 42
  • 58
612
votes
27 answers

JSON.NET Error Self referencing loop detected for type

I tried to serialize POCO class that was automatically generated from Entity Data Model .edmx and when I used JsonConvert.SerializeObject I got the following error: Error Self referencing loop detected for type System.data.entity occurs. How do…
NevenHuynh
  • 6,589
  • 5
  • 22
  • 25
605
votes
7 answers

JSON Naming Convention (snake_case, camelCase or PascalCase)

Is there a standard on JSON naming?I see most examples using all lower case separated by underscore, aka snake_case, but can it be used PascalCase or camelCase as well?
GeorgeU
  • 7,819
  • 8
  • 26
  • 38
605
votes
24 answers

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I am getting error Expecting value: line 1 column 1 (char 0) when trying to decode JSON. The URL I use for the API call works fine in the browser, but gives this error when done through a curl request. The following is the code I use for the curl…
user1328021
  • 9,110
  • 14
  • 47
  • 78
604
votes
13 answers

How do I iterate over a JSON structure?

I have the following JSON structure: [{ "id":"10", "class": "child-of-9" }, { "id": "11", "classd": "child-of-10" }] How do I iterate over it using JavaScript?
Flueras Bogdan
  • 9,187
  • 8
  • 32
  • 30
599
votes
18 answers

Chrome sendrequest error: TypeError: Converting circular structure to JSON

I've got the following... chrome.extension.sendRequest({ req: "getDocument", docu: pagedoc, name: 'name' }, function(response){ var efjs = response.reply; }); which calls the following.. case "getBrowserForDocumentAttribute": alert("ZOMG…
Skizit
  • 43,506
  • 91
  • 209
  • 269