What's the difference between Python Dictionary and JSON?

It is apples vs. oranges comparison: JSON is a data format (a string), Python dictionary is a data structure (in-memory object).

If you need to exchange data between different (perhaps even non-Python) processes then you could use JSON format to serialize your Python dictionary.

The text representation of a dictionary looks like (but it is not) json format:

>>> print(dict(zip('abc', range(3))))
{'a': 0, 'b': 1, 'c': 2}

Text representation (a string) of an object is not the object itself (even string objects and their text representations are different things e.g., "\n" is a single newline character but obviously its text representation is several characters).

Tags:

Python

Json