JSON parser for NG?

Started by Yellownakji, April 06, 2019, 23:16:59

Previous topic - Next topic

Brucey

brl.jconv won't be dealing with such complexities.

If you need to handle situations such as that, you are probably using the wrong module. brl.jconv is more suited for processing real-world data, which generally doesn't have references back to itself.

Derron

I know the relations are wrong (A knows B and B knows A)

Type TFamily
Field members:TPerson[]


Type TPerson
Field marriedTo:TPerson

Now imagine mum and dad are married to each other ... and you want to serialize the whole family (doesn't this sound nerdy?).


I am using a "person example" as you did too ;-)

Others seems to have similar issues:
https://stackoverflow.com/questions/10392293/stringify-convert-to-json-a-javascript-object-with-circular-reference

And they write about an "error message" - do you plan to have a similar error in "brl.jconv" or does the whole "toJson()" then run forever if it encounters a circular reference? Just thinking about the potential userbase of a "default module" (brl.*). If it is there to serialize your data then it should also do well for beginners. But once you store references to objects in a meta table (each serialized object gets its own entry) you can almost add the "ref" thing (which you had in persistence.mod).

If it was a module to read in external data (so they do not know about your special "ref" code or however you name it) then of course you do not need that thing and hope for the best (users not trying to "jsonify" circular referencing data). Maybe do what "stringify" does: adding a custom callback which users could utilize to add their own "circular reference solver thing" ?


bye
Ron

Brucey

I've now added custom serializing to brl.jconv, which you don't need to use for typical real-world data.

Now that I'm happy with the basic fundamentals, I can start using it myself for my json rpc thingy :-)