python json.loads / json.load truncates nested json objects? -
given following code:
import json foo = '{"root":"cfb-score","children":{"gamecode":{"attribute":"global-id"},"gamestate":{"attribute":"status-id","attribute":"status","attribute":"quarter","attribute":"minutes","attribute":"seconds","attribute":"team-possession-id","attribute":"yards-from-goal","attribute":"down","attribute":"distance","attribute":"segment-number","attribute":"active-state"},"gametype":{"attribute":"type","attribute":"detail"},"stadium":{"attribute":"name","attribute":"city","attribute":"state"},"visiting-team:team-name":{"attribute":"alias"},"visiting-team:team-code":{"attribute":"global-id"},"visiting-team:team-rank":{"attribute":"rank"}}}' bar = json.loads(foo) print json.dumps(bar)
all lowest level 'children' truncated (or maybe more overwritten) except last when using json.loads or json.load. why? json formed , can validated here: http://json.parser.online.fr/
a chunk of input:
"children" : { "gamecode" : { "attribute" : "global-id" }, "gamestate" : { "attribute" : "status-id", "attribute" : "status", "attribute" : "quarter", "attribute" : "minutes", "attribute" : "seconds", "attribute" : "team-possession-id", "attribute" : "yards-from-goal", "attribute" : "down", "attribute" : "distance", "attribute" : "segment-number", "attribute" : "active-state" },
turns chunk of output:
"children" : { "gamecode" : { "attribute" : "global-id" }, "gamestate" : { "attribute" : "active-state" },
the json well-formed (i.e., syntactically valid) semantically invalid. can't have multiple keys same value in python dict, nor in js object. if validate input @ page linked to, you'll see "js eval" pane shows "truncated" data.
if want multiple values, change format of data have 1 key array value:
"gamestate" : { "attributes": ["status-id", "status", "quarter", ...] },
(or, depending on overall data like, have gamestate
key directly link array instead of having layer of nesting under attribute
key.)
Comments
Post a Comment