<jupyter_start><jupyter_text>Pickle[pickle — Python object serialization](https://docs.python.org/3/library/pickle.html)<jupyter_code>import pickle

bmw = {'type': 'car', 'model': 'BMW 535d', 'price': '€65 000'}

with open('assets/serialized_data.txt', 'wb') as file:
    pickle.dump(bmw, file)
%cat 'assets/serialized_data.txt'
with open('assets/serialized_data.txt', 'rb') as file:
    print(pickle.load(file))<jupyter_output>{'type': 'car', 'model': 'BMW 535d', 'price': '€65 000'}<jupyter_text>In-memory Operations<jupyter_code>audi = {'type': 'car', 'model': 'Audi A5', 'price': '€60 000'}
dump = pickle.dumps(audi)
print(type(dump))
car = pickle.loads(dump)
print(car)<jupyter_output><class 'bytes'>
{'type': 'car', 'model': 'Audi A5', 'price': '€60 000'}<jupyter_text>JSON[json — JSON encoder and decoder](https://docs.python.org/3/library/json.html)<jupyter_code>import json

bmw = {'type': 'car', 'model': 'BMW 535d', 'price': '€65 000'}

with open('assets/serialized_data.json', 'w') as file:
    json.dump(bmw, file)
%cat 'assets/serialized_data.json'
with open('assets/serialized_data.json', 'r') as file:
    print(json.load(file))<jupyter_output>{'type': 'car', 'model': 'BMW 535d', 'price': '€65 000'}
{'fraction_non_alphanumeric': 0.21217105263157895, 'fraction_numerical': 0.03782894736842105, 'mean_word_length': 6.7025316455696204, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '314222', 'license': 'MIT', 'n_tokens_mistral': 519, 'n_tokens_neox': 475, 'n_words': 98, 'path': '14_objects_serialization.ipynb', 'repo_name': 'akrisanov/python_notebook', 'size': '1216'}