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
1061
votes
10 answers

How to use Jackson to deserialise an array of objects

The Jackson data binding documentation indicates that Jackson supports deserialising "Arrays of all supported types" but I can't figure out the exact syntax for this. For a single object I would do this: //json input { "id" : "junk", …
Ollie Edwards
  • 14,042
  • 7
  • 28
  • 36
1049
votes
10 answers

How to POST JSON data with Python Requests?

I need to POST a JSON from a client to a server. I'm using Python 2.7.1 and simplejson. The client is using Requests. The server is CherryPy. I can GET a hard-coded JSON from the server (code not shown), but when I try to POST a JSON to the server,…
Charles R
  • 17,989
  • 6
  • 20
  • 18
1036
votes
18 answers

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: { 'Accept': 'application/json', 'Content-Type':…
Razor
  • 27,418
  • 8
  • 53
  • 76
1026
votes
31 answers

How to parse JSON using Node.js?

How should I parse JSON using Node.js? Is there some module which will validate and parse JSON securely?
Tikhon Jelvis
  • 67,485
  • 18
  • 177
  • 214
996
votes
11 answers

Posting a File and Associated Data to a RESTful WebService preferably as JSON

In an application I am developing RESTful API and we want the client to send data as JSON. Part of this application requires the client to upload a file (usually an image) as well as information about the image. I'm having a hard time tracking down…
Gregg
  • 34,973
  • 19
  • 109
  • 214
970
votes
51 answers

Jackson with JSON: Unrecognized field, not marked as ignorable

I need to convert a certain JSON string to a Java object. I am using Jackson for JSON handling. I have no control over the input JSON (I read from a web service). This is my input JSON: {"wrapper":[{"id":"13","name":"Fred"}]} Here is a simplified…
jshree
  • 9,781
  • 3
  • 18
  • 10
928
votes
15 answers

What is the difference between YAML and JSON?

What are the differences between YAML and JSON, specifically considering the following things? Performance (encode/decode time) Memory consumption Expression clarity Library availability, ease of use (I prefer C) I was planning to use one of these…
pierrotlefou
  • 39,805
  • 37
  • 135
  • 175
917
votes
14 answers

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 figure out the problem. I am adding my code…
Pankaj Mishra
  • 20,197
  • 16
  • 66
  • 103
904
votes
18 answers

Is there any standard for JSON API response format?

Do standards or best practices exist for structuring JSON responses from an API? Obviously, every application's data is different, so that much I'm not concerned with, but rather the "response boilerplate", if you will. An example of what I…
FtDRbwLXw6
  • 27,774
  • 13
  • 70
  • 107
864
votes
31 answers

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, so if I try to use JSON.stringify() I'll get: TypeError: Converting circular structure to JSON or TypeError: cyclic object value I want to toss whatever…
Harry
  • 52,711
  • 71
  • 177
  • 261
859
votes
12 answers

Saving UTF-8 texts with json.dumps as UTF-8, not as a \u escape sequence

Sample code (in a REPL): import json json_string = json.dumps("ברי צקלה") print(json_string) Output: "\u05d1\u05e8\u05d9 \u05e6\u05e7\u05dc\u05d4" The problem: it's not human readable. My (smart) users want to verify or even edit text files with…
Berry Tsakala
  • 15,313
  • 12
  • 57
  • 80
848
votes
22 answers

How can I deserialize JSON to a simple Dictionary in ASP.NET?

I have a simple key/value list in JSON being sent back to ASP.NET via POST. Example: { "key1": "value1", "key2": "value2"} I AM NOT TRYING TO DESERIALIZE INTO STRONGLY-TYPED .NET OBJECTS I simply need a plain old Dictionary(Of String, String), or…
richardtallent
  • 34,724
  • 14
  • 83
  • 123
838
votes
13 answers

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 quickly from code. I realize that there are things…
Matt Cashatt
  • 23,490
  • 28
  • 78
  • 111
801
votes
27 answers

How to check if a string is a valid JSON string?

isJsonString('{ "Id": 1, "Name": "Coke" }') should be true and isJsonString('foo') isJsonString('
foo
') should be false. I'm looking for a solution that doesn't use try/catch because I have my debugger set to "break on all errors" and…
Chi Chan
  • 11,890
  • 9
  • 34
  • 52
771
votes
27 answers

Pretty-Printing JSON with PHP

I'm building a PHP script that feeds JSON data to another script. My script builds data into a large associative array, and then outputs the data using json_encode. Here is an example script: $data = array('a' => 'apple', 'b' => 'banana', 'c' =>…
Zach Rattner
  • 20,745
  • 9
  • 59
  • 82