Skip to content

Instantly share code, notes, and snippets.

@plq

plq/data.py

Last active Aug 29, 2015
Embed
What would you like to do?
# This example requires Spyne 2.12.2 or higher.
# Download from: https://github.com/arskom/spyne/releases/tag/spyne-2.12.2-beta
# This example throws a validation error. Remove double quotes
# around "567" to make it work.
data = b"""
{
"data" : {
"key_1" : [123, "567"],
"key_2" : ["abc","def"],
"frank_underwood" : [666.66, 333.333]
}
}
"""
from spyne import ComplexModel, Array, Integer, Unicode, Double
from spyne.util.dictdoc import json_loads
class Data(ComplexModel):
key_1 = Array(Integer)
key_2 = Array(Unicode)
frank_underwood = Array(Double)
class Wrapper(ComplexModel):
data = Data
print json_loads(data, Wrapper, validator='soft')
# Expected output:
# Wrapper(data=Data(frank_underwood=[666.66, 333.333], key_1=[123, 567], key_2=[u'abc', u'def']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.