osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bool variable with json.dumps


On 15Sep2019 09:15, Hongyi Zhao <hongyi.zhao at gmail.com> wrote:
>var = True
>
>when json.dumps on it, it will become the form `true'
>
>Why?

Because that's how the true value is spelt in JavaScript. You _are_ 
aware that JSON is "JavaScript Object Notation", are you not? So 
json.dumps translates Python values into JavaScript syntax.

This is likely to be the same reason you were wondering about None vs 
null; broadly, the Python None value serves the same purpose as the 
JavaScript null value, and therefore that is how it is expressed in 
JSON.

Cheers,
Cameron Simpson <cs at cskk.id.au>