JSON, or JavaScript Object Notation, is a simple machine-readable data-interchange format, which makes constructing API applications in JavaScript easy. For more information about JSON, visit json.org.
To return an API response in JSON format, send a parameter format in the request with a value of json.
Some simple rules are used when converting REST XML into JSON objects. Some examples illustrate this best. A single tag will be translated to JSON as follows:
<foo bar="baz" />
{
"foo": {
"bar": "baz"
}
}
Each element is represented by a JSON object. Element attributes are represented by an object member with a string value. Child elements are represented by an object member with an object value:
<foo bar="baz">
<woo yay="hoopla" />
</foo>
{
"foo": {
"bar": "baz",
"woo": {
"yay": "hoopla"
}
}
}
Element text nodes are represented as if they were an attribute, using the special name "_content":
<foo>text here!</foo>
{
"foo": {
"_content": "text here!"
}
}
For repeated elements (such as the <project> element when fetching a list of projects), an array is used as the object member value (the member key represents the element name). Each value in the array is then an object representing a child element.
<projects>
<project id="1" />
<project id="2" />
</projects>
{
"projects": {
"project": [
{
"id": "1"
},
{
"id": "2"
}
]
}
}