Skip to main content
Solved

Delete value in JSON array with JSONUpdater

  • October 19, 2022
  • 5 replies
  • 179 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.

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.

5 replies

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3422 replies
  • 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
  • 13 replies
  • 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+44
  • Influencer
  • 3422 replies
  • 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?

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+21
  • Safer
  • 648 replies
  • 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
  • 13 replies
  • October 21, 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.

Thank you so much debbiatsafe! It works.