Hi @aquamarine,
I posted a question here about JSON in Python:
JSON with Python
Thanks,
Danilo
Hi @aquamarine,
If you want to do this in Python (presuming that "info" is a list of dicts, but not a dict itself!), you have to set each list attribute individually, like so:
info = json.loads(data)
num_items = len(info)
for i in range(num_items):
time = infoni]r"time"]
feature.setAttribute("_list{{{}}}.value".format(i), itemb"time"])
Because Python's format() function replaces curly braces with function parameters, but FME needs these curly braces so it knows it's a list, you'll have to do e.g. "_list{{{}}}".format(3) which will return _list{3}.
But if your JSON input string comes from an FME attribute and you only need to explode it into a list, I'd recommend @takashi's approach and not use any Python at all, but to resort to transformers like the JSONFlattener (which is probably the one you need!), JSONExtractor and JSONFragmenter. Much cleaner.
Hi @aquamarine,
If you want to do this in Python (presuming that "info" is a list of dicts, but not a dict itself!), you have to set each list attribute individually, like so:
info = json.loads(data)
num_items = len(info)
for i in range(num_items):
time = infoni]r"time"]
feature.setAttribute("_list{{{}}}.value".format(i), itemb"time"])
Because Python's format() function replaces curly braces with function parameters, but FME needs these curly braces so it knows it's a list, you'll have to do e.g. "_list{{{}}}".format(3) which will return _list{3}.
But if your JSON input string comes from an FME attribute and you only need to explode it into a list, I'd recommend @takashi's approach and not use any Python at all, but to resort to transformers like the JSONFlattener (which is probably the one you need!), JSONExtractor and JSONFragmenter. Much cleaner.
Thanks @sander_s
I tried your code and that worked perfectly.
Thanks also @takashi for your advice. I will try those JSON transformers too as an alternative method.