Skip to main content
Solved

fme:get-json-attribute

  • October 15, 2018
  • 1 reply
  • 250 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.

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.

1 reply

takashi
Celebrity
  • 7843 replies
  • 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.