I have a large dictionary that has some large array data in it:
d = {'something': {'else': 'x'}, 'longnumbers': [1,2,3,4,54,6,67,7,7,8,8,8,6,4,3,3,5,6,7,4,3,5,6,54]}
The real dictionary has many more keys and a nested structure. When I use json.dump without indent, I get a compact, single-line output which is not readable. When I set indent, it puts newlines after every separator, including the arrays.
The numerical arrays are long and end up like this:
"longnumbers": [
1,
2,
3,
4,
54,
6,
67,
7,
7,
8,
8,
8,
6,
4,
3,
3,
5,
6,
7,
4,
3,
5,
6,
54
],
Is there any way to get pretty-printed JSON with an indent level, but without placing newlines after array elements? For the example above, I'd like something like this:
{
"longnumbers": [1, 2, 3, 4, 54, 6, 67, 7, 7, 8, 8, 8, 6, 4, 3, 3, 5, 6, 7, 4, 3, 5, 6, 54],
"something": {
"else": "x"
}
}
jsonlibrary is implemented in Python, and not especially hard to read, which provides a good base for things.json.dumpsand only override the behaviour for handling dicts, passing through all the other element types.