Skip to main content
Solved

Parse Json and do test based on value


Forum|alt.badge.img

Hello,

Lets say I have given JSON structure being passed to FME workspace as a published parameter value:

{

"users": [

{"user":"John", "age":"33"} ],

"otherParameters" : [ {"name":"parameter1", "value":"NULL"}, {"name":"parameter2", "value":"NULL"}]

}

It may contain different users and otherParameters

I would like to add a transformer/tester at the begining of the workspace flow so that if in the json there is a user with the name John and age 33 then do some things and if tha age is different or for example users list is empty do others.

What would be the best approach to do that? Thanks in advance.

Best answer by itay

You can use the json flattener to parse the parameter value and use a tester on the parsed values.

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

4 replies

Forum|alt.badge.img
  • Author
  • April 5, 2017

I I know how to do it using python private parameter. Parse JSON in script and store true/false value in private parameter but maybe there is different way using different transformers.


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • Best Answer
  • April 5, 2017

You can use the json flattener to parse the parameter value and use a tester on the parsed values.


david_r
Celebrity
  • April 6, 2017

@itay is right, the JSONFlattener might be the easiest solution. Here's the result (as shown in the Inspector) from your sample json block:

You can then use a ListExploder and/or a ListIndexer to access the individual list items.


takashi
Influencer
  • April 6, 2017

Agree. Then, in order to determine if the "users" array contains a {"user": "John", "age": "33"}, you can use a combination of ListSearcher and Tester after flattening. e.g.


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