Skip to main content
Solved

Best FME practice to convert JSON (as HTTP _response_body) input for a table (Postgres)


fbrws
BANNED
Forum|alt.badge.img+2

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

 

 

Best answer by geomancer

Passing _response_body to a JSONFlattener does the trick for me.

image

View original
Did this help you find an answer to your question?

9 replies

geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • August 24, 2023

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

image


fbrws
BANNED
Forum|alt.badge.img+2
  • Author
  • BANNED
  • August 24, 2023

Hi Geomancer,

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

Cheers


fbrws
BANNED
Forum|alt.badge.img+2
  • Author
  • BANNED
  • August 25, 2023

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?


fbrws
BANNED
Forum|alt.badge.img+2
  • Author
  • BANNED
  • August 25, 2023

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?


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • Best Answer
  • August 25, 2023

Passing _response_body to a JSONFlattener does the trick for me.

image


fbrws
BANNED
Forum|alt.badge.img+2
  • Author
  • BANNED
  • August 25, 2023

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


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • August 25, 2023
fbrws wrote:

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


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • August 25, 2023

You're welcome, have a nice day! 🌞


fbrws
BANNED
Forum|alt.badge.img+2
  • Author
  • BANNED
  • August 25, 2023
ebygomm wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings