Questions tagged [jsonpickle]

jsonpickle is a Python library for serialization and deserialization of complex Python objects to and from JSON.

jsonpickle is a Python library for serialization and deserialization of complex Python objects to and from JSON. The standard Python libraries for encoding Python into JSON, such as the stdlib’s json, simplejson, and demjson, can only handle Python primitives that have a direct JSON equivalent (e.g. dicts, lists, strings, ints, etc.). jsonpickle builds on top of these libraries and allows more complex data structures to be serialized to JSON. jsonpickle is highly configurable and extendable–allowing the user to choose the JSON backend and add additional backends.

93 questions
3
votes
1 answer

A pickle with jsonpickle (Python 3.7)

I have an issue with using jsonpickle. Rather, I believe it to be working correctly but it's not producing the output I want. I have a class called 'Node'. In 'Node' are four ints (x, y, width, height) and a StringVar called 'NodeText'. The problem…
3
votes
2 answers

jsonpickle with simplejson backend serializes Decimal as null

I'm trying to use jsonpickle in python 3.7 to serialize an object tree to json. However, all Decimals are serialized as null. I'm using simplejson as a backend, so that should be able to serialize Decimals. How do I serialize a (complex) object…
Jesse de Wit
  • 3,867
  • 1
  • 20
  • 41
3
votes
0 answers

Maximum recursion depth exceeded when passing magicmock into jsonpickle.encode()

A unit tests passes in a list of objects into a method. The method uses jsonpickle.encode on the objects. Well and good, but what to do when unit test sends list of mocked objects and runs into infinite recursion? Here is an example of the…
Nahum Timerman
  • 151
  • 1
  • 9
3
votes
1 answer

How to deal with a single value when implementing jsonpickle custom handlers?

I wrote a custom handler for jsonpickle in order to transform an enum value before serializing the object container. import jsonpickle from enum import Enum class Bar(Enum): A = 1 B = 2 class Foo: def __init__(self): …
John Difool
  • 5,572
  • 5
  • 45
  • 80
3
votes
3 answers

How to write Python dictionaries to file without make them strings?

I would like to write a list of Python dictionaries into a file. However, I need the dictionaries (and lists within) to remain dictionaries, i.e. when I load the file for processing I want them to use dictionaries and not have to work with…
user58925
  • 1,537
  • 5
  • 19
  • 28
3
votes
0 answers

jsonpickle serialize object/list to a clean json string

how to get an clean json string using jsonpickle. the output has lots of addtional fields that not in my class,for example,"py/reduce","_state","_django_version" and so on. i just want a clean output like this: [ …
phiree
  • 409
  • 6
  • 15
3
votes
0 answers

How to convert a python object from a C++ library to JSON?

I created a shared library using boost.python and py++. I can instantiate objects from types defined in the library. I want to encode/decode these objects via json. I use jsonpickle module. But, it doesn't encode attributes. I did some research.…
Q Q
  • 263
  • 2
  • 10
3
votes
1 answer

Easy way to exclude django _state attribute from jsonpickle.encode

I have a python class which is not a Django model object: class APIBase: data = object class Meta: abstract = True def toJSON(self): return jsonpickle.encode(self, unpicklable=False) However the data attribute of this…
si618
  • 16,580
  • 12
  • 67
  • 84
3
votes
3 answers

How can I get Python jsonpickle to work recursively?

I'm having trouble getting Python's jsonpickle 0.4.0 to "recurse" in to custom objects that contain custom objects. Here's sample code that shows my problem. import jsonpickle import jsonpickle.handlers class Ball(object): def __init__(self,…
Dan H
  • 14,044
  • 6
  • 39
  • 32
3
votes
4 answers

jsonpickle/json function input utf-8, output unicode?

Wrote the following two functions for storing and retrieving any Python (built-in or user-defined) object with a combination of json and jsonpickle (in 2.7) def save(kind, obj): pickled = jsonpickle.encode(obj) filename =…
zhuyxn
  • 6,671
  • 9
  • 38
  • 44
2
votes
1 answer

I have problems with jsonpickle.decode and a dictionary

I have issues decoding a JSON to a dictionary using Python 3.9.9 and jsonpickle 2.0.0. The JSON looks like follows: { "py/object" : "game.game.GameData", "origin" : { "py/object" : "player.coordinates.BasicCoordinate", "pos_x" : 67, …
Joysn
  • 987
  • 1
  • 16
  • 30
2
votes
1 answer

Serializing Spacy object to Json

I am trying to serialize Doc object from Spacy. Looks like all the hierarchy is not getting serialized. Basically I want to serialize this object to send over a Rest call. Simple test case given below: import spacy import jsonpickle nlp =…
Prateek Dorwal
  • 323
  • 3
  • 11
2
votes
1 answer

Serializing a RangeDict using YAML or JSON in Python

I am using RangeDict to make a dictionary that contains ranges. When I use Pickle it is easily written to a file and later read. import pickle from rangedict import RangeDict rngdct = RangeDict() rngdct[(1, 9)] = \ {"Type": "A", "Series":…
2
votes
1 answer

Python jsonpickle error: 'OrderedDict' object has no attribute '_OrderedDict__root'

I'm hitting this exception with jsonpickle, when trying to pickle a rather complex object that unfortunately I'm not sure how to describe here. I know that makes it tough to say much, but for what it's worth: >>> frozen =…
Scott
  • 1,247
  • 3
  • 10
  • 21
2
votes
1 answer

Write data directly to a tar archive

I am looking for a way in which I can pickle some Python objects into a combined tar archive. Further I also need to use np.save(....) to save some numpy arrays in yet the same archive. Of corse, I also need to read them later. So what I tried is a…
user4290866