I have a Debezium connector correctly listening to an outbox table and providing a JSON object as the Kafka message value.
I have read the documentation and tried various things but can't find the second part of what I need.
If I have a json object as my message can the connector filter the message such that only a specific attribute or set of attributes are included.
For example
{
"FirstObject": {
"name": "an object name"
},
"SecondObject": {
"legs": 12
}
}
Currently I receive the complete json, is there a way to say only publish SecondObject in the kafka message?
just want to know if and how I can parse a HTTP response with a dynamic name in a JSON?
I used the Azure Management API to receive the managed identities (system- and user assigned managed identities) to receive all managed identities.
With a foreach I am iterating the results.
If a resource has a system assigned managed identity and user assigned managed identity, the response looks like this:
{
"principalId": "<principalId1>",
"tenantId": "<tenantId>",
"type": "SystemAssigned, UserAssigned",
"userAssignedIdentities": {
"/subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<userAssignedIdentitiesName>": {
"principalId": "<principalId2>",
"clientId": "<clientId>"
}
}
}
Now, I would like to get the <principalId2>.
Unfortunately, the Name of the object is dynamic related to the scope of the resource /subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<userAssignedIdentitiesName>.
How can I parse the JSON to receive the needed <principalId2>?
For all other responses I can easily use the Data operations Parse JSON with the payload I inserted from the HTTP response.
Is there a way to use a wildcard? Otherwise, could I somehow just select the first object of userAssignedIdentities to receive the needed value?
Ok, this should work for you. This is the flow I tested with ...
Initialise JSON
Your JSON as a string, how you do that in your solution may differ slightly.
Initialize XPath Result
Defined as an Array and the expression is ...
xpath(xml(json(concat('{ root: ', replace(variables('JSON'), 'PrincipalId', 'principalId'), '}'))), '(//principalId)[2]')
Initialize Result
A bit more work again but defined as a String and the expression is ...
array(xpath(xml(base64ToString(variables('XPath Result')[0]?['$content'])), '//text()'))[0]
The end result should be your value ...
I want to add a JSON message as a value in the other JSON message in Microsoft Power Automate.
In more details, I have a flow that is storing a JSON message in Azure Queue storage. This message will be parsed by another flow which is sending an email. However, one of the attributes of the JSON is the email body. I want to put in the email body value, another JSON message.
What I have tried was to escape all JSON characters of the Email body with the following way
#{replace(replace(variables('emailBody'),'/','\/'),'"','\"')}
but it does not always work.
I have also tried to use the method string.encodeUriComponent which is also not nice because the message I receive is unreadable.
JSON message to send emails
{
"To": "recipient#domain.ext",
"Subject": "emailSubject",
"Body": "emailBody",
"From":"sender#domain.ext",
"CC": "ccedreceipient#domain.ext",
"Importance": "Normal",
"Is HTML": false
}
Example of the emailBody string (emailbody):
{
"Error":{
"Code":0,
"Message":"",
"ErrorCode":"",
"FailureType":""
},
"Status":"Succeeded",
"Duration":null,
"ActivityRunId":"idddididididididididididi",
"Output":"{\"pipelineName\":\"E2E Pipeline\",\"pipelineRunId\":\"ididididididi\"}",
"ExecutionStartTime":"2018-09-23T19:00:04.3644468Z",
"ExecutionEndTime":"2018-09-24T02:42:32.9746196Z",
"StatusCode":200
}
Is there any method in Microsoft Power Automate to make a sting a valid JSON value, so that I can put the email body string as a value in the Body attribute of the first JSON message?
I am sending a web request to Firebase Cloud Messaging to send a message. The raw data as sent with Content-Type:application/json" is:
{ "to":"ecO8y..._D", "data": [ {"msisdn":"+1111111" }, {"b":"c"} ] }
Firebase responds with this error message:
Field "data" must be a JSON array: [{"msisdn":"+1111111"},{"b":"c"}]
Is there something wrong with the text that I have entered for the data field?
I think the "JSON array" wording is confusing here. The data needs to be a JSON object with a single level of properties, so:
{
"to":"ecO8y..._D",
"data": {
"msisdn":"+1111111",
"b":"c"
}
}
When you try to send data from your application server to FCM, you will get 400 error, if data element contains hierarchical data or array of elements.
Data with one level of child element works.
{"message":{"topic":"users","data":{"name":"srao","pho":"38743"}}}
Data with array of element doesn't work.
{"message":{"topic":"users","data":[{"name":"grag","pho":"38743"},{"name":"boney","pho":"3899943"}]}}
Data with multiple levels or hierarchy doesn't work.
{"message":{"topic":"users","data": {"person" : {"name":"srao","pho":"38743"}}}}
I am working with Node-RED in Bluemix for IoT.
How can I parse out the individual pieces of information (like the cmdmsg and the tempr) in a function node so I can use it in other nodes in the flow?
I'm getting an error when I try (see below)
I am receiving the JSON complete message object (from an IoT in Node) that I see in my "debug" node when I set it to look at the complete message object. see the object below.
It appears to me that the JSON is formatted correctly.
I tried putting the following in the function node, but I'm getting an error that says "TypeError: Cannot read property 'tempr' of undefined"
Here is what the function parameter is:
return {payload:msg.payload.d.tempr};
and here is the message object
{
"topic": "iot-2/type/Arduino-tempsensor/id/FFFFFFFFFFFF/evt/status/fmt/json",
"payload": "{\n\"d\": {\n\"myName\": \"Arduino CF\",\n\"cmdmsg\": \"Weekly\",\n\"tempr\": -3,\n}\n}",
"deviceId": "FFFFFFFFFFFF",
"deviceType": "Arduino-tempsensor",
"eventType": "status",
"format": "json",
"_msgid": "ffffffff.55555"
}
note: I obfuscated the device ID (mac address) and msgid
Any ideas on how to parse the data out and why I'm getting an error?
Sorry, but your JSON Payload is completely messed up, it should look like this: {"d": {"myName": "Arduino CF","cmdmsg": "Weekly","tempr": -3}}
You shouldn't see any \or \nin the payload, they look like escape characters from the client side. I also believe that the last comma after the tempr value shouldn't be there for valid JSON.
I am not an Arduino expert but I have experimented with a Raspberry Pi and the Mosquitto client, this is how I can successfully send an event to IoTF:
mosquitto_pub -h <org>.messaging.internetofthings.ibmcloud.com -p 1883 -u "use-token-auth" -P "<token>" -i d:<org>:raspi:raspi2 -t iot-2/evt/message/fmt/json -m {"d":{"text":"Hello World"}}
If the paylod is correct JSON your statement return {payload:msg.payload.d.tempr}; will work.
Have you seen this: http://www.ibm.com/developerworks/cloud/library/cl-bluemix-arduino-iot2/
The JSON string you are showing should be converted to a Javascript object before you try to access its fields. To do that is as simple as wiring the arduino output to a "JSON" node, which does the conversion for you (or throws an error if the string is not valid JSON).
Wire the output of the JSON node to a debug node, if you want to see the structure of the msg object. You can also wire it to a "change" node, if you simply want to replace the msg.payload with the temperature value, for instance. You don't need any custom javascript code in a function node to do simple changes like that.
Here is a sample flow that you can import... the arduino output string is simulated by pasting your payload into a "template" node:
[{"id":"1a79abfe.b8abb4","type":"inject","z":"58c8eb7a.5496c4","name":"send output","topic":"iot-2/type/Arduino-tempsensor/id/FFFFFFFFFFFF/evt/status/fmt/json","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":2740,"wires":[["9fc678fb.ae18e8"]]},{"id":"69e91778.e0c6e8","type":"json","z":"58c8eb7a.5496c4","name":"","property":"payload","action":"","pretty":false,"x":390,"y":2800,"wires":[["d066800f.60a9b","cf991eb1.f2a1a"]]},{"id":"9d8d7da2.2a7da","type":"debug","z":"58c8eb7a.5496c4","name":"msg string","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":2740,"wires":[]},{"id":"9fc678fb.ae18e8","type":"template","z":"58c8eb7a.5496c4","name":"arduino string","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"{\n \"d\": {\n \"myName\": \"Arduino CF\",\n \"cmdmsg\": \"Weekly\",\n \"tempr\": -3\n }\n}","output":"str","x":360,"y":2740,"wires":[["69e91778.e0c6e8","9d8d7da2.2a7da"]]},{"id":"d066800f.60a9b","type":"change","z":"58c8eb7a.5496c4","name":"extract tempr","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.d.tempr","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":2860,"wires":[["af730d72.2995a"]]},{"id":"af730d72.2995a","type":"debug","z":"58c8eb7a.5496c4","name":"tempr","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":630,"y":2860,"wires":[]},{"id":"cf991eb1.f2a1a","type":"debug","z":"58c8eb7a.5496c4","name":"msg object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":2800,"wires":[]}]
As was noted, your original JSON string was not valid, because of the trailing comma -- but it is ok to have double-quotes and newlines as long as they are escaped with a "\". When the string is parsed, they are stripped out anyway.