cheshire
cheshire copied to clipboard
Pretty-Printing Feature Request: support indenting nested arrays differently than the nesting array
The specific use-case I have in mind is printing stack traces.
For example, here's some Clojure code followed by the JSON it produces.
(println
(cheshire.core/generate-string (Throwable->map (ex-info "foo" {}))
{:pretty (cheshire.core/create-pretty-printer
(assoc cheshire/default-pretty-print-options
:indent-arrays? true))}))
{
"cause" : "foo",
"via" : [
{
"type" : "clojure.lang.ExceptionInfo",
"message" : "foo",
"data" : { },
"at" : [
"clojure.core$ex_info",
"invokeStatic",
"core.clj",
4725
]
}
],
"trace" : [
[
"clojure.core$ex_info",
"invokeStatic",
"core.clj",
4725
],
[
"clojure.core$ex_info",
"invoke",
"core.clj",
4725
],
[
"boot.user$eval2476",
"invokeStatic",
"boot.user8810957904944978013.clj",
1
],
"(omitting the rest)"
],
"data" : { }
}
It would be nice if Cheshire had a convenient way to instead print the data like this:
{
"cause" : "foo",
"via" : [
{
"type" : "clojure.lang.ExceptionInfo",
"message" : "foo",
"data" : { },
"at" : ["clojure.core$ex_info", "invokeStatic", "core.clj", 4725]
}
],
"trace" : [
["clojure.core$ex_info", "invokeStatic", "core.clj", 4725],
["clojure.core$ex_info", "invoke", "core.clj", 4725],
["boot.user$eval2480", "invokeStatic", "boot.user8810957904944978013.clj", 1],
"(omitting the rest)"
],
"data" : { }
}
@MerelyAPseudonym you should be able to create your own instance of a class extending DefaultPrettyPrinter and plug that in for :pretty, that will let you indent however you would like