Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/plastbox/jref
Internal reference mechanic for JSON.
https://github.com/plastbox/jref
Last synced: about 2 months ago
JSON representation
Internal reference mechanic for JSON.
- Host: GitHub
- URL: https://github.com/plastbox/jref
- Owner: plastbox
- Created: 2014-12-04T14:33:48.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-07-26T21:07:06.000Z (over 6 years ago)
- Last Synced: 2024-10-31T12:29:52.547Z (3 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
jref
====Internal reference mechanic for JSON.
Overloads JSON.parse/stringify.
JSON.stringify
--------------
Builds a dictionary of all objects contained in the to-be-stringified object, with paths for each occurrence. Replaces every occurrence with the string "jref:shortest.path.to.object"`var foo = {name: 'Ed', car: {color:'blue'}};`
`foo.car.owner = foo; // This creates a circular reference.`
`JSON.stringify(foo); // Returns "{"name":"Ed","car":{"color":"blue","owner":"jref:this"}}"`JSON.parse
----------
Recreates all jref-references, including primitives.`var ed = JSON.parse('{"name":"Ed","car":{"color":"blue","owner":"jref:this","owner_name":"jref:this.name"}}');`
`console.log(ed.car.owner.car.owner.car.owner); // The outmost object`
`console.log(ed.car.owner_name); // 'Ed'`
`ed.car.owner_name = 'Frank';`
`console.log(ed.name); // 'Frank'`