Skip to main content
Solved

Parse Json and do test based on value

  • April 5, 2017
  • 4 replies
  • 57 views

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

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+18
  • 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
Celebrity
  • 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.