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
55
votes
9 answers

How can I serialize a numpy array while preserving matrix dimensions?

numpy.array.tostring doesn't seem to preserve information about matrix dimensions (see this question), requiring the user to issue a call to numpy.array.reshape. Is there a way to serialize a numpy array to JSON format while preserving this…
Louis Thibault
  • 20,240
  • 25
  • 83
  • 152
55
votes
3 answers

Faster XML Jackson: Remove double quotes

I have the following json: {"test":"example"} I use the following code from Faster XML Jackson. JsonParser jp = factory.createParser("{\"test\":\"example\"}"); json = mapper.readTree(jp); System.out.println(json.get("test").toString()); It…
basickarl
  • 37,187
  • 64
  • 214
  • 335
55
votes
1 answer

Json Schema validation: do not allow fields other than those declared in schema

Suppose that I have schema like fname: string lname: string age: string None of them are required. User can send me any of those attributes above but nothing else that is not declared. They can pass me fname, lname and age or all. But if they pass…
Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54
55
votes
4 answers

python sort list of json by value

I have a file consists of JSON, each a line, and want to sort the file by update_time reversed. sample JSON file: { "page": { "url": "url1", "update_time": "1415387875"}, "other_key": {} } { "page": { "url": "url2", "update_time": "1415381963"},…
icycandy
  • 1,193
  • 2
  • 12
  • 20
55
votes
2 answers

How can I add Boon or Jackson JSON parsers to Android project with Gradle?

I would like to know how can I add Boon or Jackson parser to an android project using Gradle? I found how to do so with GSON but couldn't find anything with Boon or Jackson.
Yosi199
  • 1,745
  • 4
  • 22
  • 47
55
votes
14 answers

Convert InputStream to JSONObject

I am converting InputStream to JSONObject using following code. My question is, is there any simple way to convert InputStream to JSONObject. Without doing InputStream -> BufferedReader -> StringBuilder -> loop -> JSONObject.toString(). …
AAV
  • 3,785
  • 8
  • 32
  • 59
55
votes
6 answers

Java 8 LocalDateTime deserialized using Gson

I have JSONs with a date-time attribute in the format "2014-03-10T18:46:40.000Z", which I want to deserialize into a java.time.LocalDateTime field using Gson. When I tried to deserialize, I get the error: java.lang.IllegalStateException: Expected…
fische
  • 563
  • 1
  • 4
  • 7
55
votes
2 answers

How can I customize serialization of a list of JAXB objects to JSON?

I'm using Jersey to create a REST web service for a server component. The JAXB-annotated object I want to serialize in a list looks like this: @XmlRootElement(name = "distribution") @XmlType(name = "tDistribution", propOrder = { "id",…
Alpha Hydrae
  • 2,891
  • 6
  • 26
  • 24
55
votes
3 answers

Scraping a JSON response with Scrapy

How do you use Scrapy to scrape web requests that return JSON? For example, the JSON would look like this: { "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city":…
Thomas Kingaroy
  • 575
  • 1
  • 5
  • 7
55
votes
6 answers

Getting imported json data into a data frame

I have a file containing over 1500 json objects that I want to work with in R. I've been able to import the data as a list, but am having trouble coercing it into a useful structure. I want to create a data frame containing a row for each json…
Andrew Staroscik
  • 2,675
  • 1
  • 24
  • 26
55
votes
4 answers

JSON.stringify escapes double quotes every time when stringified

I am storing JSON objects retreived from web service to objects in javascript. In many places this gets stringified(This obj goes through some plugins and it strigifies and stores it and retreives it) and it adds multiple slashes. How can I avoid it…
user88975
  • 1,618
  • 3
  • 19
  • 29
55
votes
5 answers

Recommended jQuery templates for 2012?

jQuery Templates have been deprecated for some time now. I have some data in the form of a JavaScript object that I want to format as HTML and append to the DOM. What's the best way of doing that these days? Should I build up an HTML string? Should…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
55
votes
7 answers

Python load json file with UTF-8 BOM header

I needed to parse files generated by other tool, which unconditionally outputs json file with UTF-8 BOM header (EFBBBF). I soon found that this was the problem, as Python 2.7 module can't seem to parse it: >>> import json >>> data =…
theta
  • 24,593
  • 37
  • 119
  • 159
54
votes
9 answers

json parse error with double quotes

A double quote even if escaped is throwing parse error. look at the code below //parse the json in javascript var testJson = '{"result": ["lunch", "\"Show\""] }'; var tags = JSON.parse(testJson); alert (tags.result[1]); This is throwing parse…
Varun
  • 4,054
  • 6
  • 31
  • 54
54
votes
12 answers

Updating a JSON object using Javascript

How can i update the following JSON object dynamically using javascript or Jquery? var jsonObj = [{'Id':'1','Username':'Ray','FatherName':'Thompson'}, {'Id':'2','Username':'Steve','FatherName':'Johnson'}, …
Abishek
  • 11,191
  • 19
  • 72
  • 111
1 2 3
99
100