
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can I preserve Python tuples with JSON?
There is no concept of a tuple in the JSON format. Python's JSON module converts Python tuples to JSON lists because that's the closest thing in JSON to a tuple. Immutability will not be preserved. If you want to preserve them, use a utility like a pickle or write your own encoders and decoders.
If you're using pickle, it won't store the Python temples in JSON files but in pkl files. This isn't useful if you're sending data across the web. The best way is to use your own encoders and decoders that will differentiate between lists and tuples depending on how you chose to make the encoders and decoders work.
- Related Articles
- How can I represent python tuple in JSON format?
- How I can create Python class from JSON object?
- How can I filter JSON data with multiple objects?
- How can I loop over entries in JSON using Python?
- How I can dump a Python tuple in JSON format?
- How can I subtract tuple of tuples from a tuple in Python?
- How can I convert a bytes array into JSON format in Python?
- How do I write JSON in Python?
- How can I make money with Python?
- How do I convert between tuples and lists in Python?
- Python – Filter Tuples with Integers
- How we can iterate through a Python list of tuples?
- How to split Python tuples into sub-tuples?
- How i can replace number with string using Python?
- How to preserve leading 0 with JavaScript numbers?

Advertisements