Skip to main content
Solved

Delete value in JSON array with JSONUpdater

  • October 19, 2022
  • 5 replies
  • 121 views

Hi!

I have a problem with JSONUpdater and the function "Delete From Array".

 

My case :

I have this JSON file

im1I want to delete the value 79240 in "structure_ids". In JSONUpdate, I can't write the value, it doesn't work.

im4I do write the position of this value.

How can I do this dynamically? Is there an IndexOf function on FME?

And when I write a position, here 4, in JSONUpdater, it removes 2 values ​​instead of one (79240,79389).

res1 

Thank you for your help

 

Best answer by debbiatsafe

Hi @lribot​ 

If you're familiar with XQuery, you can use the index-of function, as our XQuery transformers such as the XMLXQueryExtractor supports JSONIq extension.

If you prefer not to use XQuery, it should be possible using a JSONFlattener and ListSearcher. However, this method would not be suitable if there are multiple instances of 79240 as the ListSearcher only matches the first instance.

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

5 replies

ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • October 19, 2022

Using the index of position 4 should work here and it does correctly for me with your example.

Do you definitely only have one feature going to the update port?


  • Author
  • October 20, 2022

hi edygomm! you're right, i have two feature going to the JSONUpdater. Now I have only one and it removes 1 value in my array.

Do you have an ideas how I can get the position of a value in an JSON array?


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • October 20, 2022
lribot wrote:

hi edygomm! you're right, i have two feature going to the JSONUpdater. Now I have only one and it removes 1 value in my array.

Do you have an ideas how I can get the position of a value in an JSON array?

I don't know an FME way, I would probably end up resorting to python to remove the value from the array


debbiatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • Best Answer
  • October 20, 2022

Hi @lribot​ 

If you're familiar with XQuery, you can use the index-of function, as our XQuery transformers such as the XMLXQueryExtractor supports JSONIq extension.

If you prefer not to use XQuery, it should be possible using a JSONFlattener and ListSearcher. However, this method would not be suitable if there are multiple instances of 79240 as the ListSearcher only matches the first instance.


  • Author
  • October 21, 2022
debbiatsafe wrote:

Hi @lribot​ 

If you're familiar with XQuery, you can use the index-of function, as our XQuery transformers such as the XMLXQueryExtractor supports JSONIq extension.

If you prefer not to use XQuery, it should be possible using a JSONFlattener and ListSearcher. However, this method would not be suitable if there are multiple instances of 79240 as the ListSearcher only matches the first instance.

Thank you so much debbiatsafe! It works.


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