Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON root element

Tags:

json

xml

Does JSON require a root element as in XML case. As far as I know this is a valid JSON string.

{     "email":[         {             "type":"home",             "name":"[email protected]"         },         {             "type":"work",             "name":"[email protected]"         }     ] } 

I need to convert JSON to XML an vice versa. However although the above is valid JSON when I convert it to XML it is not valid? Am I missing something or this is normal?

like image 681
cacert Avatar asked May 03 '12 07:05

cacert


People also ask

What is a root element in JSON?

According to the modified Backus-Naur-Form on the right side pane of http://json.org/ the root element of a JSON data structure can be any of these seven types/values: Object Array String Number true false null.

Does JSON need a root element?

10.3.3 Supporting no Root ElementEclipseLink supports JSON documents without a root element. By default, if no @XmlRootElement annotation exists, the marshalled JSON document will not have a root element.

What are elements in JSON called?

The two primary parts that make up JSON are keys and values. Together they make a key/value pair. Key: A key is always a string enclosed in quotation marks. Value: A value can be a string, number, boolean expression, array, or object.

What is JSON element in Java?

JSON (JavaScript Object Notation) is a lightweight, text-based, language-independent data exchange format that is easy for humans and machines to read and write. JSON can represent two structured types: objects and arrays. An object is an unordered collection of zero or more name/value pairs.


1 Answers

The outermost level of a JSON document is either an "object" (curly braces) or an "array" (square brackets).

Any software that converts JSON to XML has to reconcile the fact that they are different data models with different rules. Different conversion tools handle these differences in different ways.

UPDATE (2021-09-03): As noted in the comments, subsequent iterations on the JSON specification allow the outermost level to be a string, number, boolean, or null.

like image 74
Michael Kay Avatar answered Sep 27 '22 23:09

Michael Kay