Are links possible in JSON?

Is it possible to assign references to objects in JSON? I have data that looks like this:

[{ name:"name", Parent:[{ name:"parentName" Parent:[{ .....//and so on }] }] }] 

I need to go through it in JavaScript, and also change the personโ€™s name . How can i do this?

+7
source share
2 answers

You can not. You can specify the path to the parent as a string and evaluate it at runtime, but since JSON is just strings, integers, arrays and dictionaries, you cannot use links.

+6
source

Old question, but some probably new answers like JSON Spec and JSON Reference https://json-spec.readthedocs.io/reference.html

 [{ "name": "John", }, { "name" : "Jack", "parent": {"$ref": "#/0"} }, ... ] 

or maybe better with JSON Path syntax http://goessner.net/articles/JsonPath/

 [{ "name": "John", }, { "name" : "Jack", "parent": {"$ref": "$.[?(@.name=='John')]"} }, ... ] 
+8
source

All Articles