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

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

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

[{
  "name": "John",
 },
 {
  "name" : "Jack",
  "parent": {".[?(@.name=='John')]"}
 }, 
...
]
Answer from Vlad on Stack Overflow
๐ŸŒ
Readthedocs
json-spec.readthedocs.io โ€บ reference.html
JSON Reference โ€” JSON Spec documentation - Read the Docs
JSON Reference allows a JSON value to reference another value in a JSON document.
๐ŸŒ
Redocly
redocly.com โ€บ learn โ€บ openapi โ€บ ref-guide
How to use JSON references ($refs)
May 28, 2025 - Reference a definition within a file by remote URL and pointer to the object. Use a JSON Pointer to the object.
Discussions

Are references possible in JSON?
Javascript doesn't have explicit objects references. What are you trying to do? ... I will traverse those values and perform some operations like changing name of the person. ... If this is about JSON, then it does not have anything to do with JavaScript, and vice versa. More on stackoverflow.com
๐ŸŒ stackoverflow.com
design - How to represent object references in JSON? - Software Engineering Stack Exchange
I am trying to figure out what's the best approach when dealing with object references in a JSON to be sent to my server for deserialization. To clarify, what I mean is how to refer to data contai... More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
June 10, 2016
json - Standard way of referencing an object by identity (for, eg, circular references)? - Stack Overflow
Is there a standard way of referencing objects by identity in JSON? For example, so that graphs and other data structures with lots of (possibly circular) references can be sanely serialized/loaded? More on stackoverflow.com
๐ŸŒ stackoverflow.com
[JSON] Is it possible to self-reference values in a JSON declaration?

No, JSON is essentially represented as a string. Nodes JSON.stringify will attempt to convert 100 + this.armour to a primitive value (in this case NaN), but other implementations of stringifywould perhaps render it as a single string that when parsed would result in a string "100 + this.armour".

If I were you, I would store the stringified object only with values that can be represented as primitive values. Then, when you parse the JSON string into a JS object, pass it into a function that will compute the additional properties that rely on other properties.

More on reddit.com
๐ŸŒ r/javascript
34
8
May 8, 2016
๐ŸŒ
Niem
niem.github.io โ€บ json โ€บ reference โ€บ json-schema โ€บ references
JSON References | NIEM GitHub
In a JSON schema, a $ref keyword is a JSON Pointer to a schema, or a type or property in a schema. ... A is the relative path from the current schema to a target schema. If A is empty, the reference is to a type or property in the same schema, an in-schema reference.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ โ€บ jsref_obj_json.asp
JavaScript JSON Reference
JavaScript Objects can be converted into JSON, and JSON can be converted back into JavaScript Objects.
๐ŸŒ
JSON Schema
json-schema.org โ€บ understanding-json-schema โ€บ reference
JSON Schema reference
Improve your JSON Schema skills with this reference, crafted by our TSC members, offering practical examples, best practices, and common pitfalls.
๐ŸŒ
GitHub
github.com โ€บ thephpleague โ€บ json-reference
GitHub - thephpleague/json-reference: A library for working with JSON References. ยท GitHub
JSON Reference is a library for resolving references.
Starred by 32 users
Forked by 9 users
Languages ย  PHP
Find elsewhere
Top answer
1 of 3
9

For inspiration, you may want to look into the way some of the json based api's (ex: json api, HAL) handle embedding.

One simple answer is to track your data in a key value store. For example

{ "/players/0" : {...}
, "/players/1" : {...}
, "/players/2" : {...}
, "/players/3" : {...}
, "/teams/0" : {...}
, "/teams/1" : {...}
}

And then you describe the players assigned to your team using local references

, "/teams/0" :
    { refs : 
        [ "/players/0"
        , "/players/1"
        ]
    }

As it happens, this scheme covers the case where you have identifiers too. Or where you only have some identifiers

, "/teams/0" :
    { refs : 
        [ "/players/0"
        , "/players/2ad8cabe-2f93-11e6-ac61-9e71128cae77"
        ]
    }

There are fancier versions of this idea (see the links).

That said, I've been down this road myself, and I really tied myself in knots until I concluded: if what you really have is a list of names, rather than a list of players, admit that to yourself, code it that way, and deal with it. It's the more honest way of representing what's going on in the domain at that point in time.

In which case, the payload of your message should look very close to:

{ "Team 1" : 
  [ "Player 1"
  , "Player 2"
  ]
, "Team 2" :
  [ "Player 3"
  , "Player 4"
  ]
}

If that makes you twitchy, remember: this isn't a description of your domain objects; it's a message. The changes it makes to your domain are a side effect. Jim Webber covers this in the introduction to this talk.

2 of 3
4

This is a really nice question.

The problem arises because you are modeling redundant information and try to avoid redundancy at the same time.

On the one hand, you have a collection of players

players = [{"id":"1"},{"id":"2"},{"id":"3"}]

On the other hand, you have a colletion of teams, which itself consist of subsets from players.

teams = [ {"id":"1", "players": [ players[0], players[1] ]} ]

This gives a composition:

players = [{id:1},{id:2},{id:3},{id:4}]

teams =[ {id:1, players:[players[0], players[1]]} ]

data = {players:players, teams:teams}

Look here for the Fiddle and watch the result.

As you see, the references cause redundant information in JSON.stringify, because you have redundant information in your data object.


The problem of avoiding redundancy arises when sending data to the server.

Take a step back.

What do you want to tell the server?

a) Here you have a list of teams, please persist it for me. I come back to you later. Oh, by the way, the teams contain the following players blablabla

b) Here you have a list of players. Keep 'em safe for me. I need them later to build `teams.

Your model shows, that you are not clear.

There are several usecases:

I) I want to create new players

IIa) I want to create new teams

IIb) I want to put players in teams

I) In a REST-context, you could issue a POST to /players.

IIa,b) You POST to /teams your collection of teams.

How to deal with the situation, that you want to save requests and do not issue a single POST for each creation of a new player (and an additional one for submitting the team)?

I would go for the following:

You have a collection of players: some of them have an id, indicating, that they were already persisted; some of them don't.

If you create teams, you issue only one POST request with the teams, containing the full player objects.

[{"name":"team1", "players":[{"id":"1", "name":"player1"}, "name":"player2"}]}, ... ] // you get the idea 

The server isn't interested in knowing explicitely how many players there are: it is implicitely clear: it's the sum of all players (which might be the sum of all players in all teams).

The server has to figure out, how to persist the players and how to set foreign keys (in case of relational DBs).

๐ŸŒ
Thephpleague
json-reference.thephpleague.com
JSON Reference - Resolve JSON References in Swagger, JSON Schema, RAML etc
JSON Reference is a library for resolving references. You can use this library to resolve references into proxy objects, allowing you to work with a JSON schema with references like a normal JSON document.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ JSON
JSON - JavaScript - MDN Web Docs
The JSON namespace object contains static methods for parsing values from and converting values to JavaScript Object Notation (JSON).
๐ŸŒ
Thephpleague
json-reference.thephpleague.com โ€บ simple-example
Simple Example - JSON Reference
This document only has internal references. Internal references use a JSON Pointer and start with an anchor (#) character.
๐ŸŒ
IETF
tools.ietf.org โ€บ html โ€บ draft-pbryan-zyp-json-ref-02
JSON Reference
JSON Reference allows a JSON value to reference another JSON value in a JSON document.
๐ŸŒ
IETF
datatracker.ietf.org โ€บ doc โ€บ html โ€บ draft-pbryan-zyp-json-ref-03
JSON Reference
JSON Reference allows a JSON value to reference another value in a JSON document.
๐ŸŒ
Reddit
reddit.com โ€บ r/javascript โ€บ [json] is it possible to self-reference values in a json declaration?
r/javascript on Reddit: [JSON] Is it possible to self-reference values in a JSON declaration?
May 8, 2016 -

Hey peeps,

Okay, so, just playing with making a wee CCG and storing the stats in a JSON object, but some of the stats are self-referential and I was wondering if there was a way around this. FOR EXAMPLE :

var cardOne = {
  name : "Example Card",
  armour : 70,
  courage : 100 + this.armour
};

Now, I know that this.armour won't work in this context, but what would?

Any help would be grand. Thanks in advance!

-P


EDIT 1: okay, seeing as this is Chrome-only project I've decided to take advantage of ES6's class notation and implement it like this :

 class Card {
     constructor(_name, _armour){
         name  = _name;
         armour = _armour;
         courage = 100 + _armour;
     }
 }
 var testCard = new Card("Example Card", 70);

...and that's how it'll stay for now, but if you can point me towards a more efficient alternative then that'd be great!


EDIT 2: as u/talmobi/ pointed out, this is the equivalent of simply writing :

var Card = function(_name, _armour){
    this.name = _name;
    this.armour = _armour;
    this.courage = 100 + _armour;
};
var testCard = new Card("Example Card", 70);

Well...that's not exactly what they said, but you can read their full comment here.

๐ŸŒ
Cswr
cswr.github.io โ€บ JsonSchema โ€บ spec โ€บ definitions_references
Definitions & References - JSON Schema
The idea of a reference such as {"$ref": "#/definitions/person"} is to use the schema that is stored under the result of evaluating the pointer /definitions/person under the same document that is defining the JSON Schema.
๐ŸŒ
Jsonref
jsonref.org
JSON REFERENCE v0.4.0 | jsonref.org
Conceptually, JSON Reference extends pure JSON decoding/encoding by parsing any JSON reference ($ref) occurrences to native language dependent reference types after decoding, and normalizing references in a JSON reference compatible way before encoding (some implementations may only support ...
๐ŸŒ
Opis
opis.io โ€บ json-schema โ€บ 2.x โ€บ references.html
JSON Schema references ($ref) | Opis JSON Schema
Consider that we have two JSON Schema documents: one validates a custom email address and the other one validates an user which must have that custom email address. In order to reuse the custom email validator we make a reference to it by using the $ref keyword.
๐ŸŒ
Newtonsoft
newtonsoft.com โ€บ json โ€บ help โ€บ html โ€บ preserveobjectreferences.htm
Preserving Object References
The PreserveReferencesHandling setting on the JsonSerializer will change how all objects are serialized and deserialized. For fine grain control over which objects and members should be serialized as a reference there is the IsReference property on the JsonObjectAttribute, JsonArrayAttribute and JsonPropertyAttribute.