Skip to main content

I need to convert:

 

{

"keys":

<ordered list of field names>

],

"values":

"<ordered list of field values, matching the keys field order>

]

}

 

What is the best way to do this in FME?

 

Input example: see attachment

 

 

The ListKeyValuePairExtractor (from FME Hub) looks like a good choice here. You will have to expose the attributes afterwards.

image


Hi Geomancer,

Thats a fast and complete answer! Thanks a lot. I will try it and report back.

Cheers


The above example works like a charm. Thanks again!

 

But its getting a little more complicated. Instead of using a JSON file I am getting a JSON response from a RES API which I invoke with the HTTPCaller. After that I use a JSONValidator, JSONFormatter and JSONFragmenter to connect to the ListExploder, the rest is the same.

(The first part of this is from Exercise: Handling JSON - FME Web Services (imgscloudapps.com))

http_jsonConfiguration of the JSONFragmenter:

http_json3Configuration of the ListExploder

http_json4But I get an error with ListExploder:

http_json2What I am doing wrong?


I get it working with the HTTPCaller in connection with TempPathnameCreator and the FeatureReader

http_json_featurereaderBut it feels cleaner (best practice, less steps) to use the response_body, although I haven't got it working yet.

What do you think?


Passing _response_body to a JSONFlattener does the trick for me.

image


Thanks again geomancer! It works perfectly. You are a genius :)


The above example works like a charm. Thanks again!

 

But its getting a little more complicated. Instead of using a JSON file I am getting a JSON response from a RES API which I invoke with the HTTPCaller. After that I use a JSONValidator, JSONFormatter and JSONFragmenter to connect to the ListExploder, the rest is the same.

(The first part of this is from Exercise: Handling JSON - FME Web Services (imgscloudapps.com))

http_jsonConfiguration of the JSONFragmenter:

http_json3Configuration of the ListExploder

http_json4But I get an error with ListExploder:

http_json2What I am doing wrong?

You are getting the error because the list you've exposed doesn't actually exist in the data if you have processed it using the JSONFragmenter setup pictured above.

Try a JSONFlattener instead, this should give you the lists you need.

Alternatively, you could save your http response to a file instead of an attribute, and then read that back in as JSON with a FeatureReader


You're welcome, have a nice day! 🌞


You are getting the error because the list you've exposed doesn't actually exist in the data if you have processed it using the JSONFragmenter setup pictured above.

Try a JSONFlattener instead, this should give you the lists you need.

Alternatively, you could save your http response to a file instead of an attribute, and then read that back in as JSON with a FeatureReader

Thx eby! Really helpfull remarks. Your input is coming together below.


Reply