I want to pretty print some JSON using the serde crate for Rust. Using serde_json::to_string
I can get this:
{"foo":1,"bar":2}
If I switch to serde_json::to_string_pretty
I get this:
{
"foo": 1,
"bar": 2
}
However, I want something inbetween with spaces to make it easier on the eye, but no linebreak so it stays on one row:
{"foo": 1, "bar": 2}
How can I achieve this? Note that the actual JSON being stringified might be more complex containing unkown levels of nesting. So just pretty printing and then stripping out the line breaks will not work.