Something is bothering me. I used JSON in several of my apps / websites, we all like it! However, today something entered my head that I had never thought about. Take a look at the following example (this is taken from http://json.org/example.html ):
{"widget": { "debug": "on", "window": { "title": "Sample Konfabulator Widget", "name": "main_window", "width": 500, "height": 500 }, "image": { "src": "Images/Sun.png", "name": "sun1", "hOffset": 250, "vOffset": 250, "alignment": "center" }, "text": { "data": "Click Here", "size": 36, "style": "bold", "name": "text1", "hOffset": 250, "vOffset": 100, "alignment": "center", "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" } }}
now, if it was expressed as XML: we would have the following:
<widget> <debug>on</debug> <window title="Sample Konfabulator Widget"> <name>main_window</name> <width>500</width> <height>500</height> </window> <image src="Images/Sun.png" name="sun1"> <hOffset>250</hOffset> <vOffset>250</vOffset> <alignment>center</alignment> </image> <text data="Click Here" size="36" style="bold"> <name>text1</name> <hOffset>250</hOffset> <vOffset>100</vOffset> <alignment>center</alignment> <onMouseUp> sun1.opacity = (sun1.opacity / 100) * 90; </onMouseUp> </text> </widget>
When looking at converting JSON to XML, I wonder if there is any way you can tell if a pair ("key": "value") is an attribute of a tag. For example, in our JSON above
"window": { "title": "Sample Konfabulator Widget", "name": "main_window",
title is represented as an attribute of the window tag, while the name is a tag in its own right, however it is not expressed anywhere (what I see).
<window title="Sample Konfabulator Widget"> <name>main_window</name>
Why it is not displayed as:
<window> <title>Sample Konfabulator Widget</title> <name>main_window</name>
Is this a way, can I indicate if a pair is an attribute of a parent tag or a child tag on its own? Sorry if my wording is bad or I am not explaining myself well.