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
56
votes
2 answers

Why Thrift, Why not HTTP RPC(JSON+gzip)

Thrift's primary goal is to enable efficient and reliable communication across programming languages. but I think HTTP-RPC can also do that, web developer almost everyone knows how to work on http and it is easier to implement HTTP-RPC(json) than…
jebbthe
  • 563
  • 1
  • 5
  • 4
56
votes
8 answers

MongoDB rename database field within array

I need to rename indentifier in this: { "general" : { "files" : { "file" : [ { "version" : { "software_program" : "MonkeyPlus", "indentifier" : "6.0.0" } } ] }…
Andrew Samuelsen
  • 5,325
  • 9
  • 47
  • 69
56
votes
6 answers

How to search nested objects with Elasticsearch

OK, I've not been able to figure this out thus far. Hoping someone can offer some insight. Given the documents below, how would I search for all documents with a video that has "test" in the video title? I'm using the HTTP API. (Basically, how do…
swatkins
  • 13,530
  • 4
  • 46
  • 78
56
votes
4 answers

Using reserved words as property names, revisited

Can a reserved word be used as an object's property name? This issue was raised indirectly in a previous Stack Overflow question: Browser support for using a reserved word as a property name in JavaScript. The answer seemed general consensus by Alex…
cc young
  • 18,939
  • 31
  • 90
  • 148
56
votes
8 answers

Exporting JSON to environment variables

If I have a JSON like this, { "hello1": "world1", "testk": "testv" } And I want to export each of these key-value pairs as environment variables, how to do it via shell script? So for example, when I write on the terminal, echo $hello1,…
Qirohchan
  • 1,057
  • 1
  • 9
  • 15
56
votes
1 answer

How to extract a field from each object in an array with jq?

I performed a cURL request to get all the users in our Gitlab server, like this. $ curl -H "Private-Token: a;sldkfja;slkdfj" https://gitlab.domain.com/api/v3/users?active=true > my_file.json and (part of) my_file.json looks like: [ { …
Chris F
  • 14,337
  • 30
  • 94
  • 192
56
votes
13 answers

Converting CSV to JSON in bash

Trying to convert a CSV file into a JSON Here is two sample lines : -21.3214077;55.4851413;Ruizia cordata -21.3213078;55.4849803;Cossinia pinnata I would like to get something like : "occurrences": [ { …
HydrUra
  • 1,336
  • 2
  • 13
  • 23
56
votes
5 answers

How to parse huge JSON file as stream in Json.NET?

I have a very, very large JSON file (1000+ MB) of identical JSON objects. For example: [ { "id": 1, "value": "hello", "another_value": "world", "value_obj": { "name": "obj1" }, …
fdmillion
  • 4,823
  • 7
  • 45
  • 82
56
votes
6 answers

Handle response - SyntaxError: Unexpected end of input when using mode: 'no-cors'

I tried a ReactJS fetch call to a REST-API and want to handle the response. The call works, i get a response, which i can see in Chrome Dev Tools: function getAllCourses() { fetch('http://localhost:8080/course', { method: 'POST', mode:…
Chilliggo
  • 605
  • 1
  • 6
  • 9
56
votes
2 answers

Using immutability-helper in React to set variable object key

I have a function I want to write in React. In my class I have a state object fields that looks like this: this.state = { step: 1, fields: { type: '', name: '', subtype: '', team: '', agreement: '' } }; I have various…
Cassidy
  • 3,328
  • 5
  • 39
  • 76
56
votes
6 answers

Rest API design with multiple unique ids

Currently, we are developing an API for our system and there are some resources that may have different kinds of identifiers. For example, there is a resource called orders, which may have an unique order number and also have an unique id. At the…
Indivon
  • 1,784
  • 2
  • 17
  • 32
56
votes
1 answer

Most efficient way to convert io.ReadCloser to byte array

I have a very simple Go webserver. It's job is to receive an inbound json payload. It then publishes the payload to one or more services that expect a byte array. The payload doesn't need to be checked. Just sent over. In this case, it receives an…
Jenny Blunt
  • 1,576
  • 1
  • 18
  • 41
56
votes
2 answers

Python json.dumps() to output minified json?

Is there any way to have python's json.dumps() output in minified form? (i.e. get rid of extraneous spaces around commas, colons etc.)
Jimmy Huch
  • 4,400
  • 7
  • 29
  • 34
56
votes
2 answers

How can I work with SQL NULL values and JSON in a good way?

Go types like Int64 and String cannot store null values, so I found I could use sql.NullInt64 and sql.NullString for this. But when I use these in a Struct, and generate JSON from the Struct with the json package, then the format is different to…
Alex
  • 5,671
  • 9
  • 41
  • 81
56
votes
4 answers

Which one to use? JSONObject from org.json VS JsonObject from javax.json

This is my first post. As a budding Android developer, I read SO posts on a near daily basis on various topics, but for this question, I didn't find any help from Google or SO. My research so far: Searching for this question was harder than normal…
Phyxius81
  • 623
  • 1
  • 5
  • 8