Last active
August 29, 2015 14:25
-
-
Save plq/3081280856ed1c0515de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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