access object in array with blanc key in json typescript - arrays

I am using storage connector in loopback to load files onto the file system. for every loaded file I am receiving a response like:
{
"files": {
"": [
{
"container": "00003",
"name": "mydoc.docx",
"type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"field": "",
"size": 23384
}
]
},
"fields": {}
}
There an issue with the returned array with a key "". The objected containing the above is called loadedFile, say I would like to print the size of the loaded file.
console.log(obj.files.""[0].size);
The above doesn't work as the array doesn't have a name in the response.
Please, can anyone point out to a solution?
Thanks in advance and Regards
T

You can access the property via the Bracket notation, rather than the Dot notation.
In your case:
console.log(obj.files[""][0].size)

Related

Logic Apps - looping through a nested array in JSON

I need to loop through this optional array (it's only the sectional of JSON I have trouble with).
As you can see from the code:
The optional bullseye has an array rings. rings has arrays of expansionCriteria and expansionCriteria may or may not have actions.
How do I iterate and get all type, threshold in expansionCriteria? I also need to access all skillsToRemove under actions, if available.
I am rather new to Logic Apps, so any help is appreciated.
"bullseye": {
"rings": [
{
"expansionCriteria": [
{
"type": "TIMEOUT_SECONDS",
"threshold": 180
}
],
"actions": {
"skillsToRemove": [
{
"name": "Claims Foundation",
"id": "60bd469a-ebab-4958-9ca9-3559636dd67d",
"selfUri": "/api/v2/routing/skills/60bd469a-ebab-4958-9ca9-3559636dd67d"
},
{
"name": "Claims Advanced",
"id": "bdc0d667-8389-4d1d-96e2-341e383476fc",
"selfUri": "/api/v2/routing/skills/bdc0d667-8389-4d1d-96e2-341e383476fc"
},
{
"name": "Claims Intermediate",
"id": "c790eac3-d894-4c00-b2d5-90cd8a69436c",
"selfUri": "/api/v2/routing/skills/c790eac3-d894-4c00-b2d5-90cd8a69436c"
}
]
}
},
{
"expansionCriteria": [
{
"type": "TIMEOUT_SECONDS",
"threshold": 5
}
]
}
]
}
Please let me know if you need more info.
To generate the schema, you can remove the name of the object at the top of the code: "bullseye":
Thank you pramodvalavala-msft for posting your answer in MS Q&A for the similar thread .
" As you are working with a JSON Object instead of an Array, unfortunately there is no built-in function to loop over the keys. There is a feature request to add a method to extract keys from an object for scenarios like this, that you could up vote for it gain more traction.
You can use the inline code action to extract the keys from your object as an array (using Object.keys()). And then you can loop over this array using the foreach loop to extract the object that you need from the main object, which you could then use to create records in dynamics."
For more information you can refer the below links:
. How to loop and extract items from Nested Json Array in Logic Apps .
.Nested ForEach Loop in Workflow. .

Can't access array/property inside JSON object

I have a JSON object (checked with typeof) and I am trying to access an array which is a property of my object. Issue I am having is that I can not get it to output anything when I to object.property
Here is my object, I am trying to access the users array inside this object. This object is assigned to a variable called policy when I do policy.users it gives undefined.
Is there something special about dealing with arrays inside objects I am missing?
{
"_id": "5cb1fcc8fa3da31baf238bdb",
"users": [
"5c8d2a0c2f1f881e2377a601",
"5cb14773c000525a8dfed406"
],
"companyID": "62137607-0f1b-49a0-88e9-a2989447f4b2",
"name": "My Policy",
"createdAt": "2019-04-13T15:14:16.651Z",
"__v": 0
}
Judging by the object schema, I believe you are using mongodb (mongoose). If so you need to add the "users" property in the "policy" schema. Like this:
users: [{
type: String
}]

Generate JSON schema

Im trying a setup a Microsoft flow. In short, I need to take JSON data retrieved from a device, and parse it so that i could reference it in the Flows below. In order to parse, i need to provide the JSON Schema to Flow. Microsoft Flow has an option to generate it from a sample payload (the results returned from the API call), but it's not generating it correctly. I'm hoping someone can help me. I need the correct JSON Schema.
The data returned from the API:
[
null,
[
{
"user_id": 2003,
"user_label": "Test1"
},
{
"user_id": 2004,
"user_label": "Test2"
}
]
]
Scheme generated in Flow from the above sample payload:
{
"type": "array",
"items": {}
}
I then tried to generate the Schema from just the data. That seemed to work, but when the Flow runs, I get a Json validation error.
Tried generating from just the data like this:
{
"user_id": 2003,
"user_label": "Test1"
}
This generated the scheme like this:
{
"type": "object",
"properties": {
"user_id": {
"type": "number"
},
"user_label": {
"type": "string"
}
}
}
So you have 2 things going on, the nested object array, and the null.
You'll need another Parse JSON after the first Parse JSON. And you'll want to filter out the null before the second Parse JSON.
It took me a while to figure out, but I hope this helps.
Start by adding the Parse JSON step to whatever step is outputting the JSON.
Now, filter the array, make sure you use the 'Expression' when comparing with null.
Add the second Parse JSON, you'll notice that you won't have the option to select the output "Item" of the Filter array step, so select 'Parse JSON' - Item for now (we will change this to use the output of the Filter JSON step in a moment)
The step should automatically change to an 'Apply to each'. In the Parse JSON 2, generate the schema with
[
{
"user_id": 2003,
"user_label": "Test1"
},
{
"user_id": 2004,
"user_label": "Test2"
}
]
Then, modify the 'Select an output from previous steps field' and change it (from the Body of the Parse JSON step) to the Body of the Filter Array step
Finally, add an action after Parse JSON 2 and select one of the fields in Parse JSON 2, this will automatically change that step to a nested Apply to each
You should end up with something like this:

ARM template array parameter

I have an ARM template with a web app alerting rule, where I want to be able to configure which e-mails get the alerts.
The snippet for the e-mail alerting action is this:
"action": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": false,
"customEmails": [
"email1#example.com",
"email2#example.com"
]
}
The same template is used for setting up production, test, and dev environments. So I would like to use a parameter for the e-mail alerting.
How can I generate an array to be used as the "customEmails" property based on either a comma separated string, or an array type parameter?
I have tried "customEmails": "[array(parameters('AlertEmailRecipients'))]", and also
"customEmails": [
[array(parameters('AlertEmailRecipients'))]
]
but neither work. I don't know how to tell it that the "customEmails" property value should come from a parameter.
I used the following using an array parameter:
parameter declaration:
"customEmails": {
"type": "array",
"metadata": {
"description": "alert email addressess"
}
}
in the parameters file:
"customEmails": {
"value": [
"email1#domain.com",
"email2#domain.com"
]
}
usage:
"customEmails": "[parameters('customEmails')]"
I found a solution. The main problem was that my comma separated list of e-mail addresses had a space after each comma.
The way I have implemented it now is like this:
Define a string parameter with a comma separated list of e-mail addresses. Don't have spaces in the list.
Define a variable like this:
"customEmails" : "[split(parameters('AlertEmailRecipients'), ',')]"
and then reference that variable in the alerting action:
"action": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": false,
"customEmails": "[variables('customEmails')]"
}
The example actually does this, but doesn't make it clear the the list of e-mails can't contain spaces.

Text inside entities in Draft.js

I've been playing with the Entity system in Draft.js. One limitation I see is that entities have to correspond with a range of text in the content they are inserted into. I was hoping I could make a zero-length entity which would have a display based on the data in the entity rather than the text-content in the block. Is this possible?
This is possible when you have a whole block. As you can see in the code example this serialised blockMap contains a block containing no text, but the character list has one entry with an entity attached to it. There is also some discussion going on regarding adding meta-data to a block. see https://github.com/facebook/draft-js/issues/129
"blockMap": {
"80sam": {
"key": "80sam",
"type": "sticker",
"text": "",
"characterList": [
{
"style": [],
"entity": "1"
}
],
"depth": 0
},
},

Resources