JSON Strings

JSON (JavaScript Object Notation) is a lightweight data-interchange format.
It is easy for humans to read and write and is considered "self-describing" and easy to understand.
It is easy for machines to parse and generate.
It is based on a subset of the JavaScript Programming Language.
This format is commonly used to send data between computers.
It provides a lightweight readable alternative to XML.


Name/Value Pairs

It consists of a field name (in double quotes), followed by a colon, followed by a value.
The value can be any of the following:


String

{ "name" : "mystring" } 

Number

{ "number" : 25 } 

Boolean

{ "toggleOnOff" : false } 

Array

{ "morethanone" : ["one", "two", "three"] } 

Object

{ "myobject" : { 
   "firstName" : "John",
   "lastName" : "Smith"
} }

Array of Objects

{ "arrayofobjects" : [ 
   { "name" : "one" },
   { "name" : "two" }
] }

Null

{ "novalue" : null } 

Examples

An "employees" field containing an array of an object (with 2 fields).

{ "employees" : [ 
  { "firstName":"John", "lastName":"Doe" },
  { "firstName":"Anna", "lastName":"Smith" },
] }

An "employee" field containing an object (with 4 fields).

{ 
  "employee" : { "employeeID":"101", "firstName":"John", "age":30, "city":"New York" }
}

An "employees" field containing an array of "employee" objects (with 4 fields).

{ "employees" : [ 
  { "employeeID":"101", "firstName":"John", "age":30, "city":"New York" }
  { "employeeID":"102", "firstName":"Anna", "age":22, "city":"London" }
] }


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext