Created
August 13, 2013 08:28
-
-
Save bjourne/6219037 to your computer and use it in GitHub Desktop.
Update version numbers
This file contains 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
import json | |
txt = """{ | |
"version" : [0, 1, 0], | |
"list" : [ | |
{"hi" : 33, "l" : [2, 3, 0], "mo" : { "version" : 3 }}, | |
{"version": [3, 4, 5]} | |
], | |
"ad" : { "foo" : 123 } | |
}""" | |
def each_obj(o): | |
yield o | |
subs = [] | |
if type(o) == dict: | |
subs = o.values() | |
elif type(o) == list: | |
subs = o | |
for v in subs: | |
for x in each_obj(v): | |
yield x | |
s = json.loads(txt) | |
for o in each_obj(s): | |
try: | |
o['version'][2] += 1 | |
except (KeyError, TypeError): | |
pass | |
print s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment