Converting JSON input for use in the Filemaker Server API

I have set up a node to receive api data from a system. It comes in JSON format:

{
   "ID": "1234567890",
   "Event":"Test Node-Red",
   "Context":"1234567-00"
}

When it appears in Node-Red, it shows up as a string with quotes

"{"ID":"1234567890","Event":"Test Node-Red","Context":"1234567-00"}"

I want to convert this data to the following format:

{ "fieldData" : 
   {
     "ID":"1234567890",
     "Event":"Test Node-Red",
     "Context":"1234567-00"
   }
}

I thought this might be as easy as using a Change Function and using a JSONata formula to change msg.payload using {"fieldData": msg.payload }

The transformation "works" but because of the quotes that were added when the data came in from the POST it doesn't work. I get:

Screen Shot 2022-11-11 at 4.39.25 PM
(The screenshot references NPI instead of ID. That is because the screenshot was taken before I updated my naming)
object
fieldData: "
{"ID":"1234567890","Event":"Test Node-Red","Context":"1234567-00"}"

Which has the extra quotes and therefore won't work with Filemaker's API

Can someone point out a better way to do this please?

Thanks!

Mike

Your incoming payload from the api is a JSON string, pass it through a Json node to convert is to an object.
e.g.

[{"id":"54b1c8d10ae639fc","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"ID\": \"1234567890\", \"Event\":\"Test Node-Red\", \"Context\":\"1234567-00\" }","payloadType":"str","x":110,"y":3700,"wires":[["4644d424090c392c"]]},{"id":"4644d424090c392c","type":"json","z":"452103ea51141731","name":"","property":"payload","action":"","pretty":false,"x":270,"y":3700,"wires":[["6e59adc03805c729"]]},{"id":"6e59adc03805c729","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.fieldData","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":3700,"wires":[["74e78bcb11dda281"]]},{"id":"74e78bcb11dda281","type":"debug","z":"452103ea51141731","name":"debug 107","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":3680,"wires":[]}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.