Better JSON

i made my own version of [json V] of @list that supports all types, inspired by another post i saw a while back (that i can’t remember the name of..)

for ADTs, add a field named _to_string to get that functionality.

LINK

feedback is appreciated!

please note, this is NOT a proper serializer, please don’t expect it to work as one!

wait this is cool~

I like it, but I think the text costumes is unnecessary – you could use a normal text representation:

yeah, but it’s also just an example for how it can interact with morphs, so i don’t think it’s that big of a deal

no, it really isn’t a big deal. just because

:slight_smile:

relatively large update, most types are now saved as objects rather than basic strings, which also means you get more info from them now. this change carries over to ADTs as well, where ADTs will always be "ADT": {"type": "__"}, with an optional "data": "..." pair if the given ADT has a _to_string method

:eyes:
image
(not released yet)

man, i’m just having too much fun with this!
image
it’s almost done..

yikes, i completely forgot about this…
well anyways, here it is now: Snap! stringifier

Other programming language implementation

Or in AverageStudentBASIC,

function recursive_list()
  local a
  a = ["hello world", "this is a test"]
  a.append(a)
  return a
end function
sub when_green_flag_clicked
  say stringify(recursive_list())
end sub

Does not do anything, but does stuck in a loop.

JSON.stringify would throw an error for circular structures like this.

It being stuck in an infinite loop is expected by the way, as we don't normally put lists inside itself so we don't cater for that. But for a truly complete stringifier, yeah, these must be checked for.


null

Yeah, and? It’s supposed to be for morphs

update: added support for javascript arrays and objects

Oh. NVM

oh, i just added morph support stuff for fun :D