Bool variable with json.dumps

Cameron Simpson cs at cskk.id.au
Sun Sep 15 05:36:20 EDT 2019


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>



More information about the Python-list mailing list