It appears to be that by default Python json
module serializes a Python list using new lines between each element, like so:
"data": [
-6.150000000000006,
-0.5,
0.539999999999992,
0.5800000000000125,
-4.6299999999999955,
12.0,
2.829999999999984,
-1.4199999999999875,
1.759999999999991,
-1.25,
I would like to serialize the contents of this list on a single line, if possible. How can I do that?
I am using json.dumps(data, indent=4)
to perform the serialization step.
2
Answers
One possible solution:
Serialize the list to a string first, then serialize the remaining contents of the dictionary.
There is a disadvantage to this:
... in other words it looks like this ...
... instead of this ...
using python version 3.8 , run this code below.
python