Json: Difference between revisions

From wikinotes
No edit summary
 
No edit summary
Line 1: Line 1:
JSON is pretty much the standard cross-platform flat-file information storage method.
A subset of javascript used for encoding structured data.
It can be a bit verbose, but it is very clear and consistent. It's syntax is derived
from javascript: all json is javascript, but the opposite is not true. In order for comments
to be valid, you must use a customized JSON parser.
 
In python, JSON errors do not return the line the error was discovered on.


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
Line 13: Line 8:
   "b":["peach","mango"] // json requires that the last list-element does not have a comma
   "b":["peach","mango"] // json requires that the last list-element does not have a comma
   },
   },
 
 
   "MyNull"        : null,
   "MyNull"        : null,
   "boolean_true"  : true,
   "boolean_true"  : true,
   "boolean_false" : false
   "boolean_false" : false
 
 
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 33: Line 28:
"boolean" = true,
"boolean" = true,
"null"    = null
"null"    = null
}
}


// compound datatypes
// compound datatypes

Revision as of 02:30, 24 June 2022

A subset of javascript used for encoding structured data.

{

   "MyCategory":{
   	"a":["apple","orange","banana"],
   	"b":["peach","mango"]						// json requires that the last list-element does not have a comma
   },

   "MyNull"        : null,
   "boolean_true"  : true,
   "boolean_false" : false

}


datatypes

JSON natively supports 6x datatypes:

// simple datatypes
{
	"string"  = "my string",
	"number"  = 9999,
	"boolean" = true,
	"null"    = null
}

// compound datatypes
{
	"object" = { "a":1, "b":1 },  // a dictionary
	"array"  = [ "a","b","c" ]
}