Skip to main content
Solved

Get JSON for a Topic

  • November 30, 2015
  • 5 replies
  • 16 views

I have a publication in FME Server that monitors a directory and sends a message to a topic when the contents of the directory change - for example, when a file gets updated.

When I start the monitor for the topic in FME Server, I get this JSON output:

Total: 1 Shown: 1 Test_DirWatch_Topic arrived at 7:40:03 { "ws_topic": "Test_DirWatch_Topic", "dirwatch_publisher_path": "C:\\\\ProgramData\\\\Safe Software\\\\FME Server\\\\Data\\\\xls\\\\New Text Document.txt", "dirwatch_publisher_content": "ENTRY_MODIFY C:\\\\ProgramData\\\\Safe Software\\\\FME Server\\\\Data\\\\xls\\\\New Text Document.txt", "dirwatch_publisher_action": "MODIFY", "fns_type": "dirwatch_publisher" }I also have am FME script that subscribes to the topic and takes action when the topic receives the JSON above. However, I only want the script to take action if the directory change is a "modify" to a certain file (in this case, "New Text Document.txt"). There are other files in this directory and I don't want the script to take action when any of them change. Is it possible for my FME script to get access to this JSON? Then I can break it down and determine which directory change occurred.Thanks

Best answer by Anonymous

That was the problem, Mark. I set the TextFile Reader to "read whole file at once" and it read the whole notification JSON, which the JSONFlattener was then able to parse.

Thanks.

View original
Did this help you find an answer to your question?
<strong>This post is closed to further activity.</strong><br /> It may be a question with a best answer, an implemented idea, or just a post needing no comment.<br /> If you have a follow-up or related question, please <a href="https://community.safe.com/topic/new">post a new question or idea</a>.<br /> If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

mark2atsafe
Safer
Forum|alt.badge.img+45
  • Safer
  • November 30, 2015

Absolutely. You need to add a textfile Reader to the workspace.

Then when you publish the workspace, click the notification properties button and select the Textfile Reader as the Notification Data Reader.

Now when you workspace is triggered by the notification, the JSON message will be passed into the workspace through this Reader. You can then process it using JSONFlattener transformers, or similar, to find out details of the notification.


  • December 1, 2015
mark2atsafe wrote:

Absolutely. You need to add a textfile Reader to the workspace.

Then when you publish the workspace, click the notification properties button and select the Textfile Reader as the Notification Data Reader.

Now when you workspace is triggered by the notification, the JSON message will be passed into the workspace through this Reader. You can then process it using JSONFlattener transformers, or similar, to find out details of the notification.

This works fine up until the jsonflattener. Then I get errors in my log file like:

JSONFlattener(JSONQueryFactory): A JSON syntax error was found at line 1, column 1

...and

JSONFlattener(JSONQueryFactory): The JSON data is incomplete: Unexpectedly encountered the end of JSON data

I have also tried parsing the text_line_data in a PythonCaller using the built-in json module with the same result. I think the problem is that the jsonflattener and the Python module don't understand the newlines in the notification output. Has anyone at Safe actually got this to work?


mark2atsafe
Safer
Forum|alt.badge.img+45
  • Safer
  • December 1, 2015
jimo wrote:

This works fine up until the jsonflattener. Then I get errors in my log file like:

JSONFlattener(JSONQueryFactory): A JSON syntax error was found at line 1, column 1

...and

JSONFlattener(JSONQueryFactory): The JSON data is incomplete: Unexpectedly encountered the end of JSON data

I have also tried parsing the text_line_data in a PythonCaller using the built-in json module with the same result. I think the problem is that the jsonflattener and the Python module don't understand the newlines in the notification output. Has anyone at Safe actually got this to work?

Some quick thoughts. Maybe set the TextFile Reader to "read whole file at once". It might be reading it as a multi-line dataset, and trying to parse a line at a time (how many features does it read?) - also perhaps set a Character Encoding for the Reader? Finally, can you put a Logger transformer in before the JSONFlattener to get a better idea of what is being returned? I suspect the problem is somehow in how the TextFile reader is reading the data.


  • Best Answer
  • December 2, 2015

That was the problem, Mark. I set the TextFile Reader to "read whole file at once" and it read the whole notification JSON, which the JSONFlattener was then able to parse.

Thanks.


mark2atsafe
Safer
Forum|alt.badge.img+45
  • Safer
  • December 2, 2015
jimo wrote:

That was the problem, Mark. I set the TextFile Reader to "read whole file at once" and it read the whole notification JSON, which the JSONFlattener was then able to parse.

Thanks.

Awesome. Glad to hear it's working.


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