How to use JSON
Syntax
This is an example of an object having 3 attributes defined:
name - String (Text)
age - Number
isAdult - Boolean (True/False)
chores - List<String> (A list of String)
{
"attributeName": value,
"attributeName": value,
"attributeName": value
}
A String will be quoted with "
on each side.
A Number can just be written directly.
A Boolean must be either true
or false
(in lower case).
A List must start and end with [
and ]
respectively, with elements spaced with a ,
.
{
"name": "John",
"age": 30,
"isAdult": true,
"chores": ["cleaning", "trash"]
}
It's what we mostly use as it's the most human readable.
{
"name": "John",
"age": 30,
"isAdult": true,
"chores": [
"cleaning",
"trash"
]
}
Also, an object can contain another one:
{
"name": "John",
"age": 30,
"isAdult": true,
"wear": {
"name": "pants",
"color": "red",
"shorts": false
}
}
Editor
You can edit JSON files with any basic text editor, but it's going to be far easier to avoid mistakes when using an editor. There's an example of one online: https://jsoneditoronline.org/
Last updated