0

JSON.NET (Newtonsoft) allows C# object graphs with circular references to be serialized and deserialized into JSON using 'PreserveReferencesHandling' as follows:

List<Person> deserializedPeople = JsonConvert.DeserializeObject<List<Person>>(json,
new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects });

Can JSON serialized this way be deserialized outside of .NET (e.g. into Javascript objects)?

Caustix
  • 569
  • 8
  • 26
  • 1
    If you mean "with object references preserved" -- it's not part of the JSON standard, so no. You'd need a JavaScript library that supports this kind of `$id`/`$ref` referencing. It's subtly different from how [existing libraries](https://www.npmjs.com/package/json-decycle) do it, which use URIs and base themselves on [this RFC](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) (which never made it out of draft). – Jeroen Mostert Feb 04 '19 at 12:59
  • Yes, I meant "with object references preserved". Thanks for the info. – Caustix Feb 04 '19 at 13:05
  • For JavaScript see [How to restore circular references (e.g. “$id”) from Json.NET-serialized JSON?](https://stackoverflow.com/q/21686499/3744182), [Resolve circular references from JSON object](https://stackoverflow.com/q/15312529/3744182) and/or [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/3744182). But your question is too broad to mark as a duplicate since you don't restrict the solution to be JavaScript only. – dbc Feb 04 '19 at 19:45

0 Answers0