Skip to main content
Solved

replace multiple json values

  • April 22, 2019
  • 1 reply
  • 291 views

dellerbeck
Contributor
Forum|alt.badge.img+6

I currently have JSON objects that are returning in FME very well. During the migration there are approx. 1,500 updates that need to be ran changing coded values to a description for storage in a data warehouse. This can be accomplished running an update that is prepopulated then passed to the "Update" port on the updater.

replace(xs:string($x(fme:get-attribute("FIELD_NAME"))),xs:string(fme:get-attribute("code")),fme:get-attribute("name"))

The issue is running 1,500 updates on 2,000 records takes 12+ minutes. The question is, is there a way to get the JSON Updater to updated multiple replacements at the same time. I have attempted to use the JSON Node updates and get errors.

Attached is a simplified version where I am attempting to change json["features"]["attributes"]/ASSETGROUP from 1,2,3,4 to One, Two, Three, Four where there is a match.

 

Thanks in advanced!!

 

Best answer by dellerbeck

All, thanks to the wonderful people at Safe I now have the answer to this!!! It's possible to pass in multiple JSON updates under a single statement using a list and a JSON_Templater. The following assumes you have a list named domain.codedValues{}. The code is the value in the JSON attribute and the name is the description to decode to.

{|

for $c at $i in fme:get-list-attribute("domain.codedValues{}.code")

let $names := fme:get-list-attribute("domain.codedValues{}.name")

return { $c : $names[$i] }

|}

 

This creates a decoding table that can be applied to an attribute in JSON using the JSON Updater with the following statement. The FIELD_NAME and code_map columns need to be supplied in the update record in order to use this statement. But once done any number of updates can be passed to the same field reducing the number of updates to a single JSON package.

 

fme:get-json-attribute("code_map")(xs:string($x(fme:get-attribute("FIELD_NAME"))))

 

Note that this is not being applied to individual records containing JSON but to a single FME Object with a JSON containing 2,000 different records. The performance went from 12 minutes per 2k to 8 seconds.

 

THANKS AGAIN SAFE!!!

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

1 reply

dellerbeck
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • Best Answer
  • April 29, 2019

All, thanks to the wonderful people at Safe I now have the answer to this!!! It's possible to pass in multiple JSON updates under a single statement using a list and a JSON_Templater. The following assumes you have a list named domain.codedValues{}. The code is the value in the JSON attribute and the name is the description to decode to.

{|

for $c at $i in fme:get-list-attribute("domain.codedValues{}.code")

let $names := fme:get-list-attribute("domain.codedValues{}.name")

return { $c : $names[$i] }

|}

 

This creates a decoding table that can be applied to an attribute in JSON using the JSON Updater with the following statement. The FIELD_NAME and code_map columns need to be supplied in the update record in order to use this statement. But once done any number of updates can be passed to the same field reducing the number of updates to a single JSON package.

 

fme:get-json-attribute("code_map")(xs:string($x(fme:get-attribute("FIELD_NAME"))))

 

Note that this is not being applied to individual records containing JSON but to a single FME Object with a JSON containing 2,000 different records. The performance went from 12 minutes per 2k to 8 seconds.

 

THANKS AGAIN SAFE!!!


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