What is wrong with this Json array syntax? - json

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"}}}}

Related

Debezium outbox payload filtering

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?

Azure Logic App - Parse JSON with dynamic key/name

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 ...

How to parse dynamic json reponse and get specific value and pass it as an input to next request

I get .json file as a response from an API and from that file I should parse and fins specific parameter and pass it as an input to the next request, how do I do that using Katalon.
If I say
response = JSON.parse("response.json");
it says it is unable to identify JSON as valid. Can someone help me out with the solution?
Your JSON is invalid, maybe it is a copy-paste issue.
The valid JSON should be
{
"responseStatusCode": "OK",
"data": {
"screenName": "employeeTimeslip",
"screenType": "Redirect",
"searchResultCount": 0,
"rows": [],
"tabs": [],
"searchParams": {
"employeeID": "000092926",
"timeslipNumber": "201900019701"
}
}
}
So, you were missing a "," between "OK" and "data" and two closing curly braces at the end of the file.
You can check JSON files for validity yourself using online JSON validators, for example, this one.
i found a way to read specific parameter from the json response file like below:
val scn = scenario("ClaimSubmission")
.exec(http("request_2")
.post("URL")
.headers(headers_2)
.body(RawFileBody("json file path"))
.check(jsonPath("$..timeslipnumber").find.saveAs("timeslipnumber")))
Timeslip number would be retrieved using : .check(jsonPath("$..timeslipnumber").find.saveAs("timeslipnumber")))

Spring cloud stream not able to retrieve Array List instead String is being picked at listener

i am sending an Array list from Producer and i am expecting to read the same arraylist at the consumer and persist into Database.
Instead of me getting the the Object i am getting and json wrapped inside the Object,which i am not able to understand why.
Below is representation of different objects.
Expexcting:
user is [Users [id=1, name=Prashantrh, nm=com.example.demo.Name#2b65d9e7]]
Pickied up at consumer side as:
[
[
{
"dmetaD":{
"id":2315,
"embedded":true,
"size":123,
"comment":"raghu",
"name":"string",
"type":"pdf",
"creationTime":"2018-05-15T20:47:48.161",
"creatorId":15001,
"creator":{
"id":15001,
"shortId":"MARC6GR",
"firstName":"V15001",
"lastName":"N15001",
"emailPref":true,
"departmentName":"RD/FNT",
"inventoryType":"P",
"langPref":"DE",
"email":"V15001.N15001#d.com"
}
},
"dCont":{
"data":"abc"
}
},
{
"dmetaD":{
"id":2316,
"embedded":true,
"size":123,
"comment":"raghu",
"name":"string",
"type":"pdf",
"creationTime":"2018-05-15T20:47:48.163",
"creatorId":15001,
"creator":{
"id":15001,
"shortId":"MARC6GR",
"firstName":"V15001",
"lastName":"N15001",
"emailPref":true,
"departmentName":"RD/FNT",
"inventoryType":"P",
"langPref":"DE",
"email":"V15001.N15001#d.com"
}
},
"dCont":{
"data":"def"
}
}
]
]
First, please provide more details as to what version of Spring Cloud Stream you are using.
That said, I am going to assume for now that you are using 2.0.0.RELEASE which means the content type of the message defaults to application/json.

JSON Deserialization on Talend

Trying to figuring out how to deserialize this kind of json in talend components :
{
"ryan#toofr.com": {
"confidence":119,"email":"ryan#toofr.com","default":20
},
"rbuckley#toofr.com": {
"confidence":20,"email":"rbuckley#toofr.com","default":15
},
"ryan.buckley#toofr.com": {
"confidence":18,"email":"ryan.buckley#toofr.com","default":16
},
"ryanbuckley#toofr.com": {
"confidence":17,"email":"ryanbuckley#toofr.com","default":17
},
"ryan_buckley#toofr.com": {
"confidence":16,"email":"ryan_buckley#toofr.com","default":18
},
"ryan-buckley#toofr.com": {
"confidence":15,"email":"ryan-buckley#toofr.com","default":19
},
"ryanb#toofr.com": {
"confidence":14,"email":"ryanb#toofr.com","default":14
},
"buckley#toofr.com": {
"confidence":13,"email":"buckley#toofr.com","default":13
}
}
This JSON comes from the Toofr API where documentation can be found here .
Here the actual sitation :
For each line retreived in the database, I call the API and I got this (the first name, the last name and the company change everytime.
Does anyone know how to modify the tExtractJSONField (or use smthing else) to show the results in tLogRow (for each line in the database) ?
Thank you in advance !
EDIT 1:
Here's my tExtractJSONfields :
When using tExtractJSONFields with XPath, you need
1) a valid XPath loop point
2) valid XPath mapping to your structure relative to the loop path
Also, when using XPath with Talend, every value needs a key. The key cannot change if you want to loop over it. Meaning this is invalid:
{
"ryan#toofr.com": {
"confidence":119,"email":"ryan#toofr.com","default":20
},
"rbuckley#toofr.com": {
"confidence":20,"email":"rbuckley#toofr.com","default":15
},
but this structure would be valid:
{
"contact": {
"confidence":119,"email":"ryan#toofr.com","default":20
},
"contact": {
"confidence":20,"email":"rbuckley#toofr.com","default":15
},
So with the correct data the loop point might be /contact.
Then the mapping for Confidence would be confidence (the name from the JSON), the mapping for Email would be email and vice versa for default.
EDIT
JSONPath has a few disadvantages, one of them being you cannot go higher up in the hierarchy. You can try finding out the correct query with jsonpath.com
The loop expression could be $.*. I am not sure if that will satisfy your need, though - it has been a while since I've been using JSONPath in Talend because of the downsides.
I have been ingesting some complex json structures and did this via minimal json libraries, and tjava components within talend.