It's an ugly hack, but I think it'll work. Remove all [ and ] characters and then write to CSV with a FeatureWriter, making sure the line with the header is the first line in the CSV, then use a FeatureReader to read it back in with the CSV reader.
I can think of two options. You start with JSONFlattener that creates the arrays, and expose array{}.array{} via AttributeExposer.
Option 1: use AttributeCreator. For New Attribute use Attribute Value array{0}.array{x} and for Attribute Value use array{1}.array{x} for x=/0..n].
You can create a custom transformer that uses ListElementCounter (on a copied and exploded array{} - array{} has a count of 2, you need the count of array{}.array{}) and iterate through all elements to create the correct number of attributes.
Option 2: use JSONTempleter to create a correct JSON with template:
{
fme:get-attribute("array{0}.array{0}"):fme:get-attribute("array{1}.array{0}"),
fme:get-attribute("array{0}.array{1}"):fme:get-attribute("array{1}.array{1}"),
fme:get-attribute("array{0}.array{2}"):fme:get-attribute("array{1}.array{2}"),
fme:get-attribute("array{0}.array{3}"):fme:get-attribute("array{1}.array{3}")
}
if you know you have a fixed number of attributes in the API response.
Then JSONFlattener to get attributes.
I also attached a sample Workspace.
I'm sure it's possible in an XMLXQueryExtractor but it's too early in the morning to wrestle with that!
It's very straightforward in python, just requires exposing the attributes afterwards
import fme
import fmeobjects
import json
def processFeature(feature):
m = json.loads(feature.getAttribute('json_example'))
arraylength = len(mx0])
for i in range(0,arraylength):
feature.setAttribute(m00]ri],me1]ti])
I can think of two options. You start with JSONFlattener that creates the arrays, and expose array{}.array{} via AttributeExposer.
Option 1: use AttributeCreator. For New Attribute use Attribute Value array{0}.array{x} and for Attribute Value use array{1}.array{x} for x=/0..n].
You can create a custom transformer that uses ListElementCounter (on a copied and exploded array{} - array{} has a count of 2, you need the count of array{}.array{}) and iterate through all elements to create the correct number of attributes.
Option 2: use JSONTempleter to create a correct JSON with template:
{
fme:get-attribute("array{0}.array{0}"):fme:get-attribute("array{1}.array{0}"),
fme:get-attribute("array{0}.array{1}"):fme:get-attribute("array{1}.array{1}"),
fme:get-attribute("array{0}.array{2}"):fme:get-attribute("array{1}.array{2}"),
fme:get-attribute("array{0}.array{3}"):fme:get-attribute("array{1}.array{3}")
}
if you know you have a fixed number of attributes in the API response.
Then JSONFlattener to get attributes.
I also attached a sample Workspace.
Thank you so much! This ended up being a great solution.