Skip to main content
Solved

fme:get-json-attribute

  • October 15, 2018
  • 1 reply
  • 175 views

I'm doing some data conversions using FME Workbench through Data Interoperability, and I'm having issues with the JSONTemplater. I am grabbing a field from a json that contains more json, and I want to leave it unaltered as part of my template. the fme:get-attribute XQuery alters the contents, and fme:get-json-attribute returns an error stating that the data does not contain any JSON text when it does.

My template expression:

 {
    "annotations": fme:get-attribute("annotations"),
    "initialStepId": fme:get-attribute("initialStepID"),
    "initialStepName": fme:get-attribute("initialStepName"),
    "steps":fme:get-attribute("steps"),
    "displayGrid": fme:get-attribute("displayGrid")
}



And an example set of data for the annotation field:

"annotations" : [ {
		"position":"299, 109, 171, 77",
		"text":"This is an annotation."
		}
	] 


Comes out like this with get-attribute... 

\"annotations\" : \"[ {
		\\\"position\\\":\\\"299, 109, 171, 77\\\",
		\\\"text\\\":\\\"This is an annotation.\\\"
                }
	]\" 



but I get this error with get-json-attribute:

diagram_details_2(XMLTemplaterFactory): 

The following error occurred while executing the fme:get-json-attribute function:

diagram_details_2(XMLTemplaterFactory): The attribute 'annotations' did not contain valid JSON text
diagram_details_2(XMLTemplaterFactory): A JSON syntax error was found at line 1, column 0
diagram_details_2(XMLTemplaterFactory): The JSON data is incomplete: Unexpectedly encountered the end of JSON data
diagram_details_2(XMLTemplaterFactory): A JSON syntax error was found at line 1, column 0
diagram_details_2(XMLTemplaterFactory): The data does not contain any JSON text

 

Anyone familiar with the tool able to help out?

Best answer by takashi

Hi @samjwestfive, as the log messages say, the value of "annotations" attribute is not a valid JSON document.

A possible way is to extract the valid JSON array part from the "annotations" and then get it with the fme:get-json-attribute function in the template. e.g.

See here to learn more about JSON basis: Introducing JSON

Hope this helps.

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

1 reply

takashi
Influencer
  • Best Answer
  • October 15, 2018

Hi @samjwestfive, as the log messages say, the value of "annotations" attribute is not a valid JSON document.

A possible way is to extract the valid JSON array part from the "annotations" and then get it with the fme:get-json-attribute function in the template. e.g.

See here to learn more about JSON basis: Introducing JSON

Hope this helps.


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