liquidsoap icon indicating copy to clipboard operation
liquidsoap copied to clipboard

stringify with varying types

Open smimram opened this issue 1 year ago • 3 comments

The following code

def f(x)
  x = x.{a = 3}
  let json.stringify s = x
  print("JSON: #{s}")
end

f({s="xx"})
f({u=2})

prints

JSON: { "a": 3 }
JSON: { "a": 3 }

Is there a way to print the other fields?...

smimram avatar Jul 21 '22 14:07 smimram

Found my way with

  s = json.stringify(x)

as third line.

smimram avatar Jul 21 '22 14:07 smimram

I'm reopening, I want to take a minute to look at this. I feel like this might be an issue for others.

toots avatar Jul 21 '22 15:07 toots

I reviewed your code and frankly I'm not sure why I originally thought a json serialization based on the type was a good idea haha. I'll think about it more but otherwise I'm of the opinion to can the let json.stringify and revert to json.stringify.

toots avatar Aug 03 '22 19:08 toots