Solved

Delete value in JSON array with JSONUpdater

  • 19 October 2022
  • 5 replies
  • 6 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

 

icon

Best answer by debbiatsafe 20 October 2022, 23:06

View original

5 replies

Badge +10

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?

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?

Badge +10

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

Userlevel 2
Badge +17

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.

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