0

I would like to know :

  • [PreserveObjectReference] Is this syntax with $ref and $id is a Json standard ?
  • Is there a way to serialize objects in Javascript using this syntax ? (automatically replacing by $ref : "id" the object it founds for a second time in the object to serialize tree).

This could be usefull to POST many objects and to create ForeignKeys between them (Entity Framework requires same reference to create only one Object when adding to DbContext). I found a way to keep the references when Deserializing it with Newtonsoft, when Automapping from dtos to EF Entities, but I don't find any solution on the Javascript side.

Thanks in advance.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • The [JSON format](https://www.json.org/) doesn't support object references (although an [IETF draft exists](http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03)). See [MDN JavaScript Reference - JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). – georgeawg Mar 27 '19 at 11:09
  • 1) No it's not standard, there is no standard. 2) Duplicate of [Resolve circular references from JSON object](https://stackoverflow.com/q/15312529), [How to restore circular references (e.g. “$id”) from Json.NET-serialized JSON?](https://stackoverflow.com/q/21686499), [Is there a Jquery function that can take a #ref id value from a parsed JSON string and point me to the referenced object?](https://stackoverflow.com/q/10747341). In fact this may be a duplicate of these three, agree? – dbc Mar 27 '19 at 16:27

0 Answers0