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
24
votes
3 answers

saving and loading objects from file using jsonpickle

I have the following simple methods for writing a python object to a file using jsonpickle: def json_serialize(obj, filename, use_jsonpickle=True): f = open(filename, 'w') if use_jsonpickle: import jsonpickle json_obj =…
user248237
16
votes
2 answers

How to exclude specific fields on serialization with jsonpickle?

I'm using SQLAlchemy extension with Flask. While serializing my models (which are also used for database operations) using jsonpickle, I want some specific attributes to be ignored. Is there a way that allows me to set those rules? SQLAlchemy adds…
mkubilayk
  • 2,477
  • 3
  • 20
  • 27
13
votes
1 answer

JSON serialized object gives error with multiprocessing calls - TypeError: XXX objects not callable error

I am using JSON serializer helper function to easy access of dictionary(basically received as JSON) objects. jsondict.py """Utilities for working with JSON and json-like structures - deeply nested Python dicts and lists This lets us iterate over…
user1992
  • 169
  • 1
  • 15
11
votes
3 answers

How to convert json to object?

I need to convert a json-string to python object. By object I mean "new" python3 object like: class MyClass(object): I found several help for example on jsonpickle documentation. But all I found are tutorials which convert object to json first and…
Sebi
  • 3,879
  • 2
  • 35
  • 62
8
votes
2 answers

AttributeError: Can't pickle local object '.'

I am trying to pickle a nested dictionary which is created using: collections.defaultdict(lambda: collections.defaultdict(int)) My simplified code goes like this: class A: def funA(self): #create a dictionary and fill with values …
zurich_ruby
  • 315
  • 1
  • 3
  • 8
8
votes
3 answers

jsonpickle datetime to readable json format

Is it possible to convert datetime into a readable JSON format (which could be used from javascript)? Currently jsonpickle provides only a binary encoded value for datetime.
Mihai H
  • 3,291
  • 4
  • 25
  • 34
7
votes
4 answers

Avoid jsonpickle using py/id pointer to another object

When an object is serialized to json using jsonpickle, I noticed objects such as datetime are stored once then future uses are stored as references value such as {"py/id":1}. Is it possible store actual value instead of reference? This reference…
ferk86
  • 2,325
  • 1
  • 23
  • 27
7
votes
1 answer

Python Pickle call constructor

I'd like to provide defaults for missing values using Python's pickle serialiser. Since the classes are simple, the defaults are naturally present in the classes's __init__ methods. I can see from pickle documentation that there is __getnewargs__.…
c z
  • 7,726
  • 3
  • 46
  • 59
7
votes
1 answer

How can I execute arbitrary code via JSON and how to sanitize the input

In the documentation of Python's jsonpickle module for JSON serialization and deserialization it states that Loading a JSON string from an untrusted source represents a potential security vulnerability. jsonpickle makes no attempt to sanitize…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
6
votes
1 answer

Model persistence in Scikit-Learn?

I am trying to save and load scikit-learn model but facing issues when the save and load are happening on different python versions. Here what I have tried: Using pickle to save a model in python3 and deserialize in python2.This works for some of…
5
votes
1 answer

Python serialize a class and change property casing using JsonPickle

With Python and JsonPickle, How do I serialize the object with a Certain Casing, eg Camel Case, Pascal, etc? The following answer below does it manually, however looking for a specific Jsonpickle solution, since it can handle complex object types…
mattsmith5
  • 540
  • 4
  • 29
  • 67
5
votes
2 answers

serializing JSON files with newlines in Python

I am using json and jsonpickle sometimes to serialize objects to files, using the following function: def json_serialize(obj, filename, use_jsonpickle=True): f = open(filename, 'w') if use_jsonpickle: import jsonpickle json_obj =…
user248237
4
votes
1 answer

Unable to decode a json string to a python object using jsonpickle

My class structure is as follows - class HelloWorld (object): def __init__(self, name, i, id): self.name = name self.i = i self.id = id The I'm creating an object p = HelloWorld('pj', 3456, '1234') and passing this…
Piyush Jajoo
  • 1,095
  • 2
  • 18
  • 27
4
votes
2 answers

google app engine jsonpickle

Has anyone got jsonpickle working on the google app engine? My logs say there is no module but there is a module as sure as you're born. i'm using jsonpickle 0.32. : No module named jsonpickle Traceback (most recent…
Cameron A. Ellis
  • 3,833
  • 8
  • 38
  • 46
3
votes
2 answers

It's a bad design to try to print classes' variable name and not value (eg. x.name print "name" instead of content of name)

The long title contain also a mini-exaple because I couldn't explain well what I'm trying to do. Nonethless, the similar questions windows led me to various implementation. But since I read multiple times that it's a bad design, I would like to ask…
Daniele
  • 134
  • 1
  • 7
1
2 3 4 5 6 7