quinnj / JSON3.jl

Other
214 stars 47 forks source link

Feature Request - Selective prettification ? #229

Open BambOoxX opened 2 years ago

BambOoxX commented 2 years ago

When working with arrays of objects it seems sometimes better to prettify the array (i.e. add a newline between consecutive objects of the array), but not prettify the objects themselves).

As an example, let's assume one has arrays objects defined as

struct Foo
    bar::Float64
    baz::Float64
end

The default json of a Vector{Foo} (assuming Foo is declared as an OrderedStruct) would look like

[
        {
               "bar": 0.672206014235892,
               "baz": -0.412477431246586
         },
         {
               "bar": -0.928845182540688,
               "baz": 0.138642524561273
         },
         {
               "bar": -0.0249912901622267,
               "baz": 0.0728279234245597
         }
]

The idea of this feature request would be to have something like a noprettify option that would allow to get e.g.

[
        {"bar": 0.672206014235892,"baz": -0.412477431246586},
        {"bar": -0.928845182540688,"baz": 0.138642524561273},
        {"bar": -0.0249912901622267,"baz": 0.0728279234245597}
]

as a result. This option could be set a bit like with the StructTypes traits with Prettyfiable(::Type{Foo}) = false or something equivalent The same argument could be relevant for some small arrays of types e.g. an array of 5 numbers that is currently print with one number per line.