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

How to map a map JSON column to Java Object with JPA

We have a big table with a lot of columns. After we moved to MySQL Cluster, the table cannot be created because of: ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 14000. This includes…
Rad
  • 4,292
  • 8
  • 33
  • 71
56
votes
7 answers

Store Hardcoded JSON string to variable

I'm having an issue storing this json string to a variable. It's gotta be something stupid I am missing here private string someJson = @"{ "ErrorMessage": "", "ErrorDetails": { "ErrorID": 111, "Description": { …
PositiveGuy
  • 46,620
  • 110
  • 305
  • 471
56
votes
2 answers

JSON unmarshaling with long numbers gives floating point number

I was marshaling and unmarshaling JSONs using golang and when I want to do it with number fields golang transforms it in floating point numbers instead of use long numbers, for example. I have the following JSON: { "id": 12423434, "Name":…
Fersca
  • 946
  • 2
  • 9
  • 10
56
votes
3 answers

Change values in JSON file (writing files)

I have a settings.json file present in the Release folder of my application. What I want to do is change the value of it, not temporarily, permanently.. That means, deleting the old entry, writing a new one and saving it. Here is the format of the…
Bone
  • 859
  • 2
  • 9
  • 17
56
votes
3 answers

Difference between toJSON() and JSON.Stringify()

if you need to read or clone all of a model’s data attributes, use its toJSON() method. This method returns a copy of the attributes as an object (not a JSON string despite its name). (When JSON.stringify() is passed an object with a toJSON()…
Shane
  • 5,517
  • 15
  • 49
  • 79
56
votes
9 answers

Add JSON serializer to every model class?

When it comes to JSON encoding in Dart, per Seth Ladd's accouncement the finally approved now official way to go is dart:convert + JSON.Encode. Let's say we have a bunch of model classes (PODOs) such as: class Customer { int Id; String…
Max
  • 9,220
  • 10
  • 51
  • 83
56
votes
5 answers

How to parse somewhat wrong JSON with Python?

I have the following JSON string coming from external input source: {value: "82363549923gnyh49c9djl239pjm01223", id: 17893} This is an incorrectly-formatted JSON string ("id" and "value" must be in quotes), but I need to parse it anyway. I have…
Serge Tarkovski
  • 1,861
  • 6
  • 19
  • 24
56
votes
5 answers

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type

I have a class like this: public class MyStok { public int STId { get; set; } public int SM { get; set; } public string CA { get; set; } public string Br { get; set; } public string BNo { get; set; } public decimal Vat { get;…
sakir
  • 3,391
  • 8
  • 34
  • 50
56
votes
14 answers

What is the best way to convert all controller params from camelCase to snake_case in Rails?

As you already know, JSON naming convention advocates the use of camelCase and the Rails advocates the use of snake_case for parameter names. What is the best way to convert all request's params to snake_case in a rails controller? From this: { …
a.s.t.r.o
  • 3,261
  • 5
  • 34
  • 41
56
votes
2 answers

is not JSON serializable

I have the following ListView import json class CountryListView(ListView): model = Country def render_to_response(self, context, **response_kwargs): return json.dumps(self.get_queryset().values_list('code', flat=True)) But I get…
tuna
  • 6,211
  • 11
  • 43
  • 63
56
votes
3 answers

What is the difference between "required" vs "optional" in JSON Schema

Sometimes, I noticed the following JSON Schemas: { "type": "object", "properties": { "address": { "type": "string", "required": true } } } vs { "type": "object", …
Cory
  • 14,865
  • 24
  • 57
  • 72
56
votes
5 answers

Ignoring property when deserializing

I have a simple interface with getter and setter for a property. public interface HasMoney { Money getMoney(); void setMoney(Money money); } I have another class UserAccount which implements this interface. public class…
Nishant Nagwani
  • 1,160
  • 3
  • 13
  • 26
56
votes
8 answers

Want to hide some fields of an object that are being mapped to JSON by Jackson

I have a User class that I want to map to JSON using Jackson. public class User { private String name; private int age; private int securityCode; // getters and setters } I map this to a JSON string using - User user =…
sonicboom
  • 4,928
  • 10
  • 42
  • 60
56
votes
2 answers

Forcing application/json MIME type in a view (Flask)

I can't figure out how to force the MIME type application/json for a view in Flask. Here is a simple view I've thrown together for demonstration purposes: @app.route("/") def testView(): ret = '{"data": "JSON string example"}' return…
Jay
  • 18,959
  • 11
  • 53
  • 72
56
votes
2 answers

@JsonProperty annotation on field as well as getter/setter

I have inherited a certain bit code that has the @JsonProperty annotation on getter/setters. The purpose is so that when the object is serialized using the Jackson library, the fields have that specific name. Current code: private String…
OceanBlue
  • 9,142
  • 21
  • 62
  • 84