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

Json Schema example for oneOf objects

I am trying to figure out how oneOf works by building a schema which validates two different object types. For example a person (firstname, lastname, sport) and vehicles (type, cost). Here are some sample objects: {"firstName":"John",…
Stanimirovv
  • 3,064
  • 8
  • 32
  • 56
57
votes
4 answers

JSON Post request for boolean field sends false by default

Hi I am sending a JSON Post request using the FireFox RestClient. My JSON Request is as below: { "firstName": "Test", "lastName": "1", "isActive": 1 } My POJO has isActive field as below private boolean isActive; My Controller is define as…
NewQueries
  • 4,841
  • 11
  • 33
  • 39
57
votes
3 answers

Serializing list to JSON

I am sending information between client and Django server, and I would like to use JSON to this. I am sending simple information - list of strings. I tried using django.core.serializers, but when I did, I got AttributeError: 'str' object has no…
gruszczy
  • 40,948
  • 31
  • 128
  • 181
57
votes
5 answers

How do I compress a Json result from ASP.NET MVC with IIS 7.5

I'm having difficulty making IIS 7 correctly compress a Json result from ASP.NET MVC. I've enabled static and dynamic compression in IIS. I can verify with Fiddler that normal text/html and similar records are compressed. Viewing the request, the…
Gareth Saul
  • 1,307
  • 1
  • 9
  • 19
57
votes
8 answers

ActiveRecord serialize using JSON instead of YAML

I have a model that uses a serialized column: class Form < ActiveRecord::Base serialize :options, Hash end Is there a way to make this serialization use JSON instead of YAML?
Toby Hede
  • 36,755
  • 28
  • 133
  • 162
57
votes
4 answers

Can I LINQ a JSON?

This is the JSON I get from a request on .NET: { "id": "110355660738", "picture": { "data": { "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/1027085_12033235063_5234302342947_n.jpg", "is_silhouette": false } …
markzzz
  • 47,390
  • 120
  • 299
  • 507
57
votes
6 answers

Loading a .json file into c# program

I am trying to move my website from XML based config files to JSON based ones. Is there a way to load in a .json file in so that it turns into the object? I have been searching the web and I cannot find one. I already have the .xml file converted…
ford prefect
  • 7,096
  • 11
  • 56
  • 83
57
votes
4 answers

sort json object in javascript

For example with have this code: var json = { "user1" : { "id" : 3 }, "user2" : { "id" : 6 }, "user3" : { "id" : 1 } } How can I sort this json to be like this - var json = { "user3" : { …
julian
  • 4,634
  • 10
  • 42
  • 59
57
votes
9 answers

AngularJS - Server side validation and client side forms

I am trying to understand how to do the following things: What is the accepted way of declaring a form. My understanding is you just declare the form in HTML, and add ng-model directives like so: ng-model="item.name" What to send to the server. I…
Dominic Bou-Samra
  • 14,799
  • 26
  • 100
  • 156
57
votes
3 answers

Can JSON numbers be quoted?

Can there be quotes around JSON numbers? In most of the search links, it seems that numbers do not "require" quotes. But, should the parsers accept both "attr" : 6 and "attr" : "6"? If MyParser has a method getInt to get a number given the key,…
Unreal user
  • 1,045
  • 2
  • 9
  • 13
57
votes
2 answers

How do I use requirejs to load a static JSON file?

I want to keep a JSON document to store some simple data and I want to require this document and use the JSON object in a define() call so I can use it. This is not an async call. I mean it should be for development but I do want to compile the file…
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
57
votes
6 answers

downloading jackson.codehaus.org jar

I need to download a json parser so I go to the jackson.codehaus.org website. Instead of a convenient link to click and download the jar/jars, they have me going in circles. Does anyone know where the jars are -- exactly?
kasavbere
  • 5,873
  • 14
  • 49
  • 72
57
votes
11 answers

json_encode(): Invalid UTF-8 sequence in argument

I'm calling json_encode() on data that comes from a MySQL database with utf8_general_ci collation. The problem is that some rows have weird data which I can't clean. For example symbol �, so once it reaches json_encode(), it fails with…
Artjom Kurapov
  • 6,115
  • 4
  • 32
  • 42
57
votes
1 answer

Jackson ObjectMapper with UTF-8 encoding?

Is there a way to tell Jackson to use UTF-8 encoding when using ObjectMapper to serialize and deserialize Objects?
Patricio
  • 919
  • 1
  • 6
  • 8
56
votes
5 answers

How to map JSON field names to different object field names?

What is the equiv way in Jackson json annotation for the following jax-b annotations? I need to produce json rather than xml and need to know the conventional jackson annotations that is equivalently denoted in jax-b. rename a field. use getters…
Blessed Geek
  • 21,058
  • 23
  • 106
  • 176