Skip to main content
Question

Send JSON via websocket

  • September 11, 2019
  • 3 replies
  • 10 views

Forum|alt.badge.img+1

I'm trying to send a message to the websocket server on my FME Cloud instance. I can successfully transmit the following:

 

{"ws_op" : "send","ws_msg" : "hello"}

 

But I want to send a JSON message as "ws_msg", so I tried:

 

{"ws_op" : "send","ws_msg" : fme_get_attribute("payload")}

 

Which isn't received on the other end, similarly to if we have an incorrect message, i.e. without the "send message"-format from the documentation of the WebSocketSender. I would guess it's something with the quotes around the message, but I am unable to escape quotes in the message formatting window.

 

So, how can I send a JSON message (Payload-attribute attached) to a websocket using FME?

 

{
      "type": "Feature",
      "properties": {
       "icon-image": "pulsing-dot-blue"},
      "geometry": {
        "type": "Point",
        "coordinates": [
          17.3016102,
          59.6615453
        ]
      }
    }

 

3 replies

Forum|alt.badge.img+1
  • Author
  • September 11, 2019

Using a JSON Templater works, in combination with this line:

 

ws_op: 'send', ws_msg: '@Value(Dummy)' }

 

JSON Templater creates an attribute into Dummy, which is then processed. But how does '@Value(Dummy)' differ from fme_get_attribute("payload")? 


denniswilhelm
Contributor
Forum|alt.badge.img+11
  • Contributor
  • September 12, 2019
fhilding wrote:

Using a JSON Templater works, in combination with this line:

 

ws_op: 'send', ws_msg: '@Value(Dummy)' }

 

JSON Templater creates an attribute into Dummy, which is then processed. But how does '@Value(Dummy)' differ from fme_get_attribute("payload")? 

fme_get_attribute automatically escapes " to \"  which isn't done by the @Value command. In a JSONTemplater you can also use fme:get-json-attribute("yourAttributeName") to explicitly load insert valid JSON values.


Forum|alt.badge.img+1
  • Author
  • September 12, 2019
denniswilhelm wrote:

fme_get_attribute automatically escapes " to \\" which isn't done by the @Value command. In a JSONTemplater you can also use fme:get-json-attribute("yourAttributeName") to explicitly load insert valid JSON values.

Awesome! Wish this was in the documentation for the transformer, or... really anywhere!


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