Objek Python dari Type Set bukan 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)
Bacem OBEY