Issue 34721: json module loads function (original) (raw)

This is intentional, the parsed in JSON doesn't necessarily have to have an object at the root. This is also what allows you to do:

json.loads("[]") []

This behavior is also consistent with browsers, try this in your browser's dev console:

JSON.parse("123") 123 JSON.parse('"123"') "123" JSON.parse('[]') []

More technically, look at the JSON standard here: https://www.json.org/

As you can see, the root value is an "element", which is of type "value" surrounded by some whitespace. Values can be any of these:

value object array string number "true" "false" "null"