jsony
jsony copied to clipboard
Feature suggestion: toJson with optional `pretty` bool parameter
toJson proc accepts optional pretty bool parameter to pretty-print output with newlines and indents.
One one hand adding pretty to the json lib might make it slower and harder to code for as well as how should user hooks work, they would have to worry about formatting as well...
But then maybe I should make pretty be a separate step from turning stuff into json. Maybe pretty should be self contained where it reads and outputs json. I could see some thing like this.
Maybe some thing like this?
proc toJsonPretty*[T](v: T): string =
## Pretty print json (does not aim to be fast).
let nonPrettyStr = v.toJson()
parseJson(nonPrettyStr).pretty()
Thanks for looking at this. That makes sense on separating the concerns.
My hack at the moment is actually similar e.g. obj.toJson().fromJson().pretty().
As context, my current use case is scraping/monitoring a data set and outputting "pretty-printed" json files into a git repo, so any optimizations on speed would be helpful.