Skip to main content
Question

Json Query


sunsilk11
Contributor
Forum|alt.badge.img+6

Hi, I have a json string, which I have flattened to a bunch of attributes (about 30), all have values 0 or 1. 

I'd like to query each attribute and output the list of attributes which have value 1 only. All of the attributes may be 0 for some records.

Any suggestions what's the best way to achieve this. I could use a stringConcatenator, and find whether 1 exists, but it wouldn't give me list of attributes

3 replies

geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • July 9, 2021

Update: improved version using the custom transformer AttributeListExploder in my post below.

 That was fun! I learned something new about FME today, and I got to help a fellow FME user (I hope). What a great way to spend a Friday afternoon!

Find_Attributes_with_Value_1This solution makes use of Lists. The AttributeExploder set to Exploding type 'List' creates a list, the ListElementFilter (from FME Hub) keeps only those elements from the list that meet a condition you set. Finally the ListConcatenator writes the names of those elements to an attribute.

Find_Attributes_with_Value_1_Feature_InformationSee the attached workspace for more details.


sunsilk11
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • July 9, 2021

works perfectly. Good to know about ListElementFilter also

Thanks


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • July 12, 2021

I just found out it works almost perfectly.

When there are other elements in the list that contain the value 1 (such as ObjID on one feature) that element is also kept, so for that feature the attribute name ObjID appears in the results from ListConcatenator as well.

So it would be better to replace the AttributeExploder with the AttributeListExploder (from FME Hub). This custom transformer lets you select what attributes to add to the list (whereas the AttributeExploder takes all attributes).

Find_Attributes_with_Value_1_version_2See the attached workspace.


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