This is a simple questions that is really only a footnote in something I am writing:
Is any valid JSON not also valid Python?
I know the converse is true, i.e. Python data structures and scalars allow a variety of constructs that are not JSON. But for the most part, JSON seems to be a subset of Python syntax for defining (some) data structures.
The obvious stuff is covered. Strings are strings. Ints are ints. JSON "numbers" are read as Python floats (although RFC 8259 does not mandate that interpretation vs. fixed point, for example). Dicts are dicts. Lists are lists.
But maybe something in some obscure corner violates the subset relationship. For example, is there anything in the encoding of Unicode outside the BMP that is directly incompatible? Or maybe within Unicode surrogate pairs?
Or maybe something with numbers where some large number of digits after the decimal would be technically valid JSON but not Python? (I don't think so, but just trying to think of scenarios).
jsonmodule to load JSON data instead of simply reading the text.jsonmodule, etc. This is more pedantic. Show me a string such that:python json.loads(jstr) != eval(jstr)Or where the eval() raises an exception but json.loads() does not.{1: true}will immediately be an invalid Python. Think about what you are asking. Besides, Python has strict indentation requirements where JSON doesn't care for. One is a data interchange format, the other is a programming language. You're comparing apples to oranges.