#Pretty printing Json

1 messages · Page 1 of 1 (latest)

lime mantle
wide jolt
stable adder
#

you cant pretty print the json type

#

its encoded as you construct it

lime mantle
#

do you mean the json type cannot be pretty printed at all or with pprint?

mental stag
#

Calling pprint.debug with a json.Json doesn't work for me, gives the pictured error.

It'd be great to be able to pretty print the stringified JSON, i.e. with indenting and whitespace similar to what JSON.stringify(json, null, 2) gives you in JS. I opened a GH issue for it a while back and it was closed because with the reason that it would impact the performance of the non pretty printing path. I'm not sure why that is though, I'd assumed they'd be separate paths. Issue link: https://github.com/gleam-lang/json/issues/13.

Maybe JSON pretty printing belongs best as a new feature in the existing pprint package?

GitHub

🐑 Work with JSON in Gleam! Contribute to gleam-lang/json development by creating an account on GitHub.

lime mantle
mental stag
#

Yes looks like it would easy for JS (or could DIY easily) - might have been different before the recent v2 changes. Not sure if there's anything for pretty printing in Erlang's json module that was added in v27

lime mantle
#

yeah I don't think there is unfortunately

#

could be why then, if its only able to be supported by a builtin implementation on JS target