This might be a silly question but I am quite new using json, and I do not fully understand this:
(Using this online compiler)
import json
print("Hello World")
print(json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':')))
As far as I've understood: json.dumps takes an object and produces a string
And the output seems right:
[1,2,3,{"6":7,"4":5}]
I searched for a way to make it more readable, and there is a parameter called indent
that does the job well. But I do not understand why the output is different.
print(json.dumps([1,2,3,{'4': 5, '6': 7}], indent=2, separators=(',',':')))
Output:
[
1,
2,
3,
{
"6":7,
"4":5
}
]
Shouldn't it be first "4":5, "6":7
and not the other way around?
(Expected result?)
[
1,
2,
3,
{
"4":5,
"6":7
}
]
Thanks in advance!