jquery - How to get the JSON with duplicate keys completely in javascript -
i trying json url, in response object duplicate keys removed. there way fetch without removing duplicate keys? here js code
$('document').ready(function(){ var s = $.getjson("new.json"); console.log(s); }); following new.json
{ "s": "wae", "s": "asd" } but in console getting json object follows
responsejson: object s: "asd" thanks in advance
keys in json object should unique. otherwise last key value 1 presented when requesting key. having keys same makes more difficult differentiate between attributes of object. whole point of key make accessible , available.
to around always:
- change keys in json
change json contain array
{"s": ["wae","asd"]}
the javascript object notation (json) data interchange format) (rfc7159) says:
the names within object should unique.
in context should must understood specified in rfc 2119
should word, or adjective "recommended", mean there may exist valid reasons in particular circumstances ignore particular item, full implications must understood , weighed before choosing different course.
rfc 7159 explains why unique keys good:
an object names unique interoperable in sense
software implementations receiving object agree on name-value mappings. when names within object not
unique, behavior of software receives such object is
unpredictable. many implementations report last name/value pair
only. other implementations report error or fail parse the
object, , implementations report of name/value pairs,
including duplicates.json parsing libraries have been observed differ whether or not make ordering of object members visible calling software. implementations behavior not depend on member
ordering interoperable in sense not be
affected these differences.
Comments
Post a Comment