Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python object of type set is not json serializable

Use the jsonpickle module to make Python set JSON serializable
Steps:
    1- Install jsonpickle using pip. pip install jsonpickle
    2- Execute jsonpickle.encode(object) to serialize custom Python Object.
Example:
import json
import jsonpickle
from json import JSONEncoder
sampleSet = {25, 45, 65, 85}

print("Encode set into JSON using jsonpickle")
sampleJson = jsonpickle.encode(sampleSet)
print(sampleJson)

# Pass sampleJson to json.dump() if you want to write it in file

print("Decode JSON into set using jsonpickle")
decodedSet = jsonpickle.decode(sampleJson)
print(decodedSet)

# to check if we got set after decoding
decodedSet.add(95)
print(decodedSet)
Comment

PREVIOUS NEXT
Code Example
Python :: random.choices in python 
Python :: pandas reset index from 0 
Python :: split and only grab first part of string 
Python :: python dictionary sort by value then alphabetically 
Python :: python new date 
Python :: is coumn exist then delete in datafrmae 
Python :: compare times python 
Python :: functools reduce python 
Python :: python code execution time 
Python :: deleting a file using python 
Python :: sub matrix python 
Python :: regex_2/_regex.c:50:10: fatal error: Python.h: No such file or directory 
Python :: django admin create project 
Python :: pandas read_excel 
Python :: mapping with geopandas 
Python :: fibinacci python 
Python :: python list contain list 
Python :: form action in django 
Python :: map python 3 
Python :: how to remove time in datetime in python 
Python :: windows how to store filepath as variabley python 
Python :: Python Tkinter RadioButton Widget 
Python :: python set timezone windows 
Python :: Python not readable file 
Python :: sklearn random forest 
Python :: python check for alphanumeric characters 
Python :: time in python code 
Python :: replace multiple column values pandas 
Python :: python count 
Python :: pandas df describe() 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =