Solved

fme:get-json-attribute

  • 15 October 2018
  • 1 reply
  • 20 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?
icon

Best answer by takashi 16 October 2018, 01:00

View original

1 reply

Userlevel 2
Badge +17

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