August 25, 2019, 12:26:25 AM

Author Topic: JSON parser for NG?  (Read 779 times)

Offline Brucey

  • Jr. Member
  • **
  • Posts: 83
Re: JSON parser for NG?
« Reply #30 on: August 12, 2019, 08:26:29 PM »
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.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2337
Re: JSON parser for NG?
« Reply #31 on: August 12, 2019, 08:55:03 PM »
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

Offline Brucey

  • Jr. Member
  • **
  • Posts: 83
Re: JSON parser for NG?
« Reply #32 on: August 15, 2019, 05:21:08 PM »
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 :-)