Converting data from XML to JSON

Map parameters are set up using an XML file created by a developer. The data must me converted to JSON. to make it easy to work with at the client side.

XML (or eXtensible Markup Language) is a text format used to store structured data to provide information interchange between programs.

JSON (or JavaScript Object Notation) is a text format for transmitting data, based on JavaScript and commonly used with this language.

Compare:

xml:

<SolidColorBrush Id="solid1" Color="#ffCBE5F2" />

<SolidColorBrush Id="solid2" Color="#ffA6C4D7" />

JSON:

"SolidColorBrush" :

[{"@Id" : "solid1", "@Color" : "ffCBE5F2"},

{"@Id" : "solid2","@Color" : "ffA6C4D7"}]

See above XML code that contains brushes description. The code has been converted to JSON.

NOTE. After item attributes are converted, they are preceded with the character @.

See also:

Creating a DHTML Map