Skip to content

Instantly share code, notes, and snippets.

@plq
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plq/3081280856ed1c0515de to your computer and use it in GitHub Desktop.
Save plq/3081280856ed1c0515de to your computer and use it in GitHub Desktop.
# 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