Mm77
Mm77

Reputation: 95

Logic app- how to retrieve json data from dynamic property name

Here's my json - Here I want to retrieve json content from "Property - Dynamic content". Where, dynamic content part might vary for every json request. How do I filter this by a dynamic name?

{
  "Attributes": 
  {
    "Property1": {
      "Data1": {
        "Value": "50"
  }
},
"Property2": {
  "Data2": {
    "Value": "50"
  }
},
"Property - Dynamic content": {
  "Data3": {
    "Value": "50"
  },
  "Data4": {
    "Value": "50"
  }
}

} }

Upvotes: 2

Views: 3888

Answers (2)

Mm77
Mm77

Reputation: 95

I was able to get what I need using inline code - javascript - If anyone else is looking for the same - here it is - This will give json from Property - dynamic content element.

var data = Object.keys(workflowContext.trigger.outputs.body.Attributes);

var key = data.filter(s => s.includes('Property')).toString(); // to get element - Property - dynamic content

return workflowContext.trigger.outputs.body.Attributes[key];

Upvotes: 1

Hury Shen
Hury Shen

Reputation: 15724

For your requirement, please refer to my logic app below:

1. I initialized a variable and store the json same with yours to simulate your situation.

enter image description here

2. Then use "Parse JSON".

enter image description here

Please notice the schema of "Parse JSON" show as:

{
    "properties": {
        "Attributes": {
            "properties": {
                "Property - Dynamic content": {
                    "type": [
                        "object",
                        "array"
                    ]
                },
                "Property1": {
                    "properties": {
                        "Data1": {
                            "properties": {
                                "Value": {
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        }
                    },
                    "type": "object"
                },
                "Property2": {
                    "properties": {
                        "Data2": {
                            "properties": {
                                "Value": {
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        }
                    },
                    "type": "object"
                }
            },
            "type": "object"
        }
    },
    "type": "object"
}

Please pay attention to the type of Property - Dynamic content in schema above. Since the content of Property - Dynamic content is either "object" or "array", so I set both "object" and "array" as the type of Property - Dynamic content.

3. Then I initialized a variable named "result" to get the value which you want. enter image description here

As we use both type "object" and "array" in the schema for Property - Dynamic content, so you may not find it in the "Dynamic content" selection. You can input its value by expression as the screenshot above. The whole expression is: body('Parse_JSON')?['Attributes']?['Property - Dynamic content']

Upvotes: 1

Related Questions