Is use of @attributes in JSON non-standard or standard? -


we're adding json output existing api outputs xml, make mobilehtml integration easier. however, our developer has queried use of @attributes appearing in json output.

our original xml looks like:

<markers>     <marker id="11906" latitude="52.226578"     ... 

and json comes out as:

callbackname({"marker":[{"@attributes":{"id":"11906","latitude":"52.226578" .... 

our developer has stated:

"although '@attributes' legal json, seems break dot notation, can't call data.@attributes. can call data['@attributes'], there's workaround, seems safer avoid @-symbol, unless there's reason it."

the xml->json(p) conversion done using:

$xmlobject = simplexml_load_string ($data); $data = json_encode ($xmlobject); 

i want make our api easy-to-integrate possible, , therefore use standard stuff possible. we're using native php json_encode function, i'd surprised if it's doing non-standard.

is use of @attributes non-standard? problem our api bit broken in terms of using <marker id..> rather <marker><id> ?

the json standard specifies , isn't valid; doesn't set convention. there's nothing inherently wrong using property names aren't valid javascript identifiers.

however, developer points out, make more awkward use result in js, makes impossible use dot notation. on gripping hand, using attributes simple content seen "good xml" , you're using using default, built-in tools convert xml json. i'd tend consider enough reason leave is.

if me, i'd @ how difficult implement custom xml -> json converter. if it's simple , straightforward, go route , avoid @attribute (it make json smaller , simpler). if it's hassle, however, missing out on dot notation isn't end of world. @ worst, var attr = data.marker["@attributes"]; around issue.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -