Logic app read property of json stored in variable - azure-logic-apps

I have this json in a Logic App variable. I want to 'id' property of this JSON and use further. How to get this id property value?
My json is:
{
"id": 1,
"name": "John bright",
"username": "Lily",
"email": "abc#aabc.com",
}

You said your json is a variable, but you don't mention which type it's stored.
Stored as string. In this way the whole json is a string, it's not supported to select property. So you need parse it to Json with Parse JSON action then you will be able to select property. About the Parse JSON Schema, just click the Use sample payload to generate schema and paste your json value, it will generate. And select your property just use the #{body('Parse_JSON')?['name']}, it will work.
If it's stored as an Object, it will be easier to do it, just use expression variables('test1')['name'] to get it.

Use the Parse Json action and use your payload as a "Use sample payload to generate schema". After that, id will be listed as a Dynamic content from the Parse Json action.

Related

How the body of the PATCH request should look like to change values in an array?

I need to change the values of the object on a third-party resource. I authorize there by token. Passing data via JSON
There is an object, for example, with this structure:
{"Fields": {"anyid": {"Blocks": []}},
"name": "123"}
I want to insert a value into this object, in the "Blocks" array: [], insert a value, for example "anyword".
Write PATCH request
{"Fields": {"anyid": {"Blocks": ["anyword"]}}}
and i get an error - 500 "Object reference not set to an instance of an object"
but, if i will write
{"Name": "any name"},
the query works absolutely correctly and the value changes.
The problem is directly with the nested fields within Fields, can you tell me how the body of the request should look so that I can change the values in the array?

How to create JSON object dynamically in Azure Logic Apps?

I have a workflow in Azure Logic App that execute an API call to get custom fields values from Trello card. Then, I put a 'for each' step to get the definition (field name) of every custom field. This is made by calling another method of Trello API. I want to create a JSON object based in the values I've got from these API calls. The format of JSON is as simple as:
{
"name1": "value1",
"name2": "value2",
...
}
Edit:
I have an initial object with this schema:
{
"Cel": "",
"City": "",
"CreatedOn": "",
"Lead": "",
"Mail": "",
"Brand": "",
"Name": "",
"Salesperson": ""
}
It's a simple json object with key:value pairs.
I want to set the object properties inside a for each loop. I got the values of the fields from Trello API (returns an array like):
[{"id":"5fbdb5da1626b7499d690ebf","value":{"date":"2020-11-09T15:00:00.000Z"},"idCustomField":"5fbdb5cee93a775e4a9405e5","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946e31680220774095ed9","idValue":"5fa9464bd260145aacba03ed","idCustomField":"5fa9462327f2c331a184a483","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946e0dafc5b7ead25411a","value":{"text":"Lilia Noemi Cabral"},"idCustomField":"5fa9454303ee497b7b99772a","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946bf8697d18d58b73ac1","value":{"text":"Tania"},"idCustomField":"5fa94518f410418c57662fd0","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946c3a2ee2771d26ba30e","value":{"text":"tania#gmail.com"},"idCustomField":"5fa945088fc819708d157c5b","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946bc38b469081857ea9a","value":{"text":"Asuncion"},"idCustomField":"5fa944fe9d7af62b3806c8b6","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946b82bbaf938c4c3c341","value":{"number":"098234567"},"idCustomField":"5fa944e59527342399f460e2","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946b32aad4d323ba0648e","value":{"text":"Tania Cardozo Olivera"},"idCustomField":"5fa944d779089c6ca5cf534b","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"}]
I put a for each step to iterate and parse the field value. I got the field name with another call to Trello API, which return this response:
{"id":"5fa94518f410418c57662fd0","idModel":"5f988b8cb225cc7ac34deae9","modelType":"board","fieldGroup":"53eb88d2e4cde013cb9f03e7500ad1a00a4c82f153f9165f7b1ec554f4cc2d74","display":{"cardFront":true},"name":"Name","pos":81920,"type":"text","limits":{"customFieldOptions":{"perField":{"status":"ok","disableAt":50,"warnAt":45}}},"isSuggestedField":false}
So, I matched the idCustomField to get the field name and field value. Now I want to set the property in the initial declared object (each property name is equal to custom field name in Trello)
I've tried using a compose step with:
setProperty(variables('Object'),body('Parse_JSON')?['name'],body('Parse_JSON2')?['text'])
And later set the variable object to the compose outputs, but doesn't work fine. The result object doesn't have all the properties set. My idea is to set all the object properties inside the for each loop.
What could I be doing wrong?
Is there a way to achieve that in Azure Logic Apps?
Thanks in advance!
You should use
setProperty(variables('object'), body('Parse_JSON')?['name'], body('Parse_JSON_2')?['value']?['text'])
instead of
setProperty(variables('Object'),body('Parse_JSON')?['name'],body('Parse_JSON2')?['text'])
================================Update===================================
Your problem may be caused by the "For each" loop run in parallel, so please try with the steps below (Note: if you do this change, when you want to change back, sometimes it will show error message when you click "Save" of you logic app. So please create another logic app for test or make a backup copy of logic app):
Click the "Settings" of your "For each" loop.
Then enable Concurrency Control and set Degree of Parallelism as 1.

Angular 2+ mongoose, let on array doesn't work due to ID object

I am trying to do a let on an array of data that is requested from a mongoose server.
This works if I don't return the ID object with the rest of the Json data.
However I want to add the ID data as params to routernavigate to another component.
Is there an easy way of receiving the id as a string rather then an object?
You can use following to stringify your object data
JSON.parse(JSON.stringify(''));//use your result object as parameters
as a example JSON.parse(JSON.stringify(result['_id']));

How to get tabs in angular forms based on given xml file?

I have to get number of input tabs or fields based on given xml or json file.
example : If xml has 3 tags, then form should contain 3 input fields.
Same with JSON.
You can use ng-repeat on service response array of objects. And also you can create new scope variable & assign unique property of response array object to it. Then you can have as many number of input fields based on service data & also dynamic ng-model on them to handle their model data to submit it.
This is small example which demonstrates your requirement: http://jsfiddle.net/DrQ77/
For xml response, better use xml to json library plugins to convert it to json data https://github.com/abdmob/x2js. Or prefer server side sending json data (with implementing xml to json functionality at server side).

angularjs $resource.query with complex structure

all my rest API for the query (e.g. /clubs) return an object that is of this form:
{
"total": 10,
"results": [...]
}
the $resourece.query expect an array.
what's the correct way to parse this response?
Should I override in the definition of the resource the query setting isArray: false? (if I set the functions to override the query do I've to re-set all the other methods such as get save etc?)
Should I create a parseFunction to parse the result and return an array? if so, how?
how can I create a my resource in a way that I don't have to replicate the code for every resource? basically extending the current $resource object to override the configuration, or the parsing function.
What are you receiving back is an object and not an array, so use $resource.get, then you can access the results array from the object

Resources