open JSON file with Excel Power Query - json

Hi I have the following JSON file format (sample) and please any one let me know how to open the file in excel columns or tables. Thank you.
{ "fields": [ "id", "name", "definition" ], "items": [ { "ref": "#28:1", "id": "1", "values": [ "1", "ABC", "This is file 1." ], "relationships": [ { "toTable": "Table 1", "relationships": [ { "id": "1", "extra": {} } ] }, { "toTable": "Table 2", "relationships": [ { "id": "1", "extra": {} }, { "id": "7", "extra": {} }, { "id": "11", "extra": {} }, { "id": "24", "extra": {} } ] }, { "toTable": "Table 3", "relationships": [ { "id": "22", "extra": {} }, { "id": "31", "extra": {} } ] }, { "toTable": "Table 4", "relationships": [ { "id": "37", "extra": {} }, { "id": "38", "extra": {} }, { "id": "50", "extra": {} } ] } ] }, { "ref": "#28:2", "id": "2", "values": [ "2", "DEF", "This is file 2." ], "relationships": [ { "toTable": "Table 1", "relationships": [ { "id": "3", "extra": {} } ] }, { "toTable": "Table 2", "relationships": [ { "id": "1", "extra": {} }, { "id": "5", "extra": {} }, { "id": "24", "extra": {} } ] }, { "toTable": "Table 3", "relationships": [ { "id": "1", "extra": {} } ] }, { "toTable": "Table 4", "relationships": [ { "id": "5", "extra": {} }, { "id": "7", "extra": {} } ] } ] }, { "ref": "#28:3", "id": "3", "values": [ "3", "GHI", "This is file 3." ], "relationships": [ { "toTable": "Table 1", "relationships": [ { "id": "1", "extra": {} } ] }, { "toTable": "Table 2", "relationships": [ { "id": "2", "extra": {} }, { "id": "5", "extra": {} }, { "id": "8", "extra": {} } ] }, { "toTable": "Table 4", "relationships": [ { "id": "5", "extra": {} }, { "id": "8", "extra": {} } ] } ] } ], "relatedObjects": [ { "TableId": "Table 1", "totalItems": 151, "totalHits": 1, "fields": [ "id", "Number", "name" ], "items": [ { "ref": "#165:28", "id": "1", "values": [ "1", "ASRU" ] } ] }, { "TableId": "Table 2", "totalItems": 282, "totalHits": 5, "fields": [ "id", "fullName", "firstName" ], "items": [ { "ref": "#68:83", "id": "5", "values": [ "5", "ABC", "Acer" ] } ] } ] }
Tried excel power query to create reports using the above JSON file format.

spreadsheet view, click the “Data” tab on the ribbon at the top of Excel. In the “Data” sections, “Import and Transform” section, select the product from Get Data > From File > JSON. Open your computer's standard "Import" window. Here, open the width where your JSON file is located.

Related

extract collection from json based on a condition using logic app

I am trying to Extract and sum a particular value using group by from json collection in azure logic app. Trying to achieve this by applying "Condition" connector. My Json file looks like below:
"Release": [
{
"O_Id": "D_13211175",
"R_ID": "D_132111751",
"Res": [
{
"A_Id": "32323222",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904601622__1",
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1",
},
]
}
]
I want to calculate the sum of Qty group by I_Id from array Res using logic app connector "Condition".
Note: As Res is an array, there can be repetition I_Id with same value, hence, the requirement to get the Qty count based on I_Id
There are few ways to achieve your requirement but here is one of the workaround that worked when reproduced from our end.
Firstly, I have initialised a temporary integer variable to iterated inside the "Res" Array using Until Loop by checking the length of "Res" using the below expression.
length(body('Parse_JSON')?['Release']?[0]?['Res'])
Inside Until I have used condition action to check if I_Id is same using the below expression to the left.
body('Parse_JSON')?['Release']?[0]?['Res']?[variables('temp')]?['I_Id']
and below expression to the right
body('Parse_JSON')?['Release']?[0]?['Res']?[add(variables('temp'),1)]?['I_Id']
Then if the condition satisfies I'm adding the Qty using the expression as below.
add(body('Parse_JSON')?['Release']?[0]?['Res']?[variables('temp')]?['Qty'],body('Parse_JSON')?['Release']?[0]?['Res']?[add(variables('temp'),1)]?['Qty'])
Here is the flow of my logic app
[Optional step]
Considering the bigger picture, I have initialzed another variable quantity and added the resultant of Compose 4 to Qty variable
RESULTS:
Considering the below sample JSON
{
"Release": [
{
"O_Id": "D_13211175",
"R_ID": "D_132111751",
"Res": [
{
"A_Id": "32323222",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904601622__1"
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1"
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 5,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1"
}
]
}
]
}
Here is the result
To avoid confusion try the below code view in your resource
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": {
"Release": [
{
"O_Id": "D_13211175",
"R_ID": "D_132111751",
"Res": [
{
"A_Id": "32323222",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904601622__1"
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 1,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1"
},
{
"A_Id": "32323223",
"F_Qty": 1,
"I_Id": "828929",
"OL_Id": "1",
"Qty": 5,
"RL_Id": "1",
"Unique_Identifier": "5970703818904692717__1"
}
]
}
]
},
"runAfter": {},
"type": "Compose"
},
"Compose_3": {
"inputs": "#variables('Qty')",
"runAfter": {
"Until": [
"Succeeded"
]
},
"type": "Compose"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "temp",
"type": "integer",
"value": 0
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_2": {
"inputs": {
"variables": [
{
"name": "Qty",
"type": "integer",
"value": 0
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "#outputs('Compose')",
"schema": {
"properties": {
"Release": {
"items": {
"properties": {
"O_Id": {
"type": "string"
},
"R_ID": {
"type": "string"
},
"Res": {
"items": {
"properties": {
"A_Id": {
"type": "string"
},
"F_Qty": {
"type": "integer"
},
"I_Id": {
"type": "string"
},
"OL_Id": {
"type": "string"
},
"Qty": {
"type": "integer"
},
"RL_Id": {
"type": "string"
},
"Unique_Identifier": {
"type": "string"
}
},
"required": [
"A_Id",
"F_Qty",
"I_Id",
"OL_Id",
"Qty",
"RL_Id",
"Unique_Identifier"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"O_Id",
"R_ID",
"Res"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Until": {
"actions": {
"Condition": {
"actions": {
"Compose_2": {
"inputs": "#add(outputs('Compose_4'),variables('Qty'))",
"runAfter": {
"Compose_4": [
"Succeeded"
]
},
"type": "Compose"
},
"Compose_4": {
"inputs": "#add(body('Parse_JSON')?['Release']?[0]?['Res']?[variables('temp')]?['Qty'],body('Parse_JSON')?['Release']?[0]?['Res']?[add(variables('temp'),1)]?['Qty'])",
"runAfter": {},
"type": "Compose"
},
"Set_variable": {
"inputs": {
"name": "Qty",
"value": "#outputs('Compose_2')"
},
"runAfter": {
"Compose_2": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"expression": {
"and": [
{
"equals": [
"#body('Parse_JSON')?['Release']?[0]?['Res']?[variables('temp')]?['I_Id']",
"#body('Parse_JSON')?['Release']?[0]?['Res']?[add(variables('temp'),1)]?['I_Id']"
]
}
]
},
"runAfter": {},
"type": "If"
},
"Increment_variable": {
"inputs": {
"name": "temp",
"value": 1
},
"runAfter": {
"Condition": [
"Succeeded"
]
},
"type": "IncrementVariable"
}
},
"expression": "#equals(variables('temp'), length(body('Parse_JSON')?['Release']?[0]?['Res']))",
"limit": {
"count": 60,
"timeout": "PT1H"
},
"runAfter": {
"Initialize_variable_2": [
"Succeeded"
]
},
"type": "Until"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

Search object a element and return the element and parents

I want to make a search from object JSON but when a I found the element I want to be returned with his previous parents.
[
{
"name": "level1",
"children": [
{
"name": "level2",
"children": [
{
"name": "level3a",
"children": [
{
"name": "text",
"more": "info"
},
{
"name": "text Abc",
"more": "info"
}
]
},
{
"name": "level3b",
"children": [
{
"name": "text-C",
"more": "info"
},
{
"name": "search",
"more": "info"
}
]
},
{
"name": "level3c",
"children": [
{
"name": "info-C",
"more": "info"
},
{
"name": "search",
"more": "info"
}
]
}
]
}
]
},
{
"name": "level1",
"children": [
{
"name": "level2a",
"children": [
{
"name": "level3",
"children": [
{
"name": "text A",
"more": "info"
}
]
},
]
},
{
"name": "level2b",
"children": [
{
"name": "level3",
"children": [
{
"name": "text X",
"more": "info"
}
]
},
]
}
]
}
]
For example: if want to search "text" I want result like this
[
{
"name": "level1",
"children": [
{
"name": "level2",
"children": [
{
"name": "level3a",
"children": [
{
"name": "text",
"more": "info"
},
{
"name": "text Abc",
"more": "info"
}
]
},
{
"name": "level3b",
"children": [
{
"name": "text-C",
"more": "info"
}
]
}
]
}
]
},
{
"name": "level1",
"children": [
{
"name": "level2a",
"children": [
{
"name": "level3",
"children": [
{
"name": "text A",
"more": "info"
}
]
},
]
},
{
"name": "level2b",
"children": [
{
"name": "level3",
"children": [
{
"name": "text X",
"more": "info"
}
]
},
]
}
]
}
]
Things to considerer
only "search" in level 3 children by name property
if one o more childrens matches the search, return all of them
Basically I need to filter by the last level of object with elements matches with the search and return them with them parents.

Converting JSON Object to Flat Structure using Logic Apps

So I have been using this logic apps template to hit the Google Analytics API and the response is in this format
{
"reports": [
{
"columnHeader": {
"dimensions": [
"ga:date",
"ga:campaign",
"ga:country",
"ga:browser",
"ga:deviceCategory",
"ga:sourceMedium",
"ga:socialNetwork",
"ga:region"
],
"metricHeader": {
"metricHeaderEntries": [
{
"name": "ga:users",
"type": "INTEGER"
},
{
"name": "ga:sessions",
"type": "INTEGER"
},
{
"name": "ga:newUsers",
"type": "INTEGER"
},
{
"name": "ga:bounces",
"type": "INTEGER"
},
{
"name": "ga:pageviews",
"type": "INTEGER"
},
{
"name": "ga:sessionDuration",
"type": "TIME"
},
{
"name": "ga:hits",
"type": "INTEGER"
},
{
"name": "ga:goalCompletionsAll",
"type": "INTEGER"
},
{
"name": "ga:goalConversionRateAll",
"type": "PERCENT"
}
]
}
},
"data": {
"rows": [
{
"dimensions": [
"20200312",
"(not set)",
"India",
"Chrome",
"desktop",
"(direct) / (none)",
"(not set)",
"Tamil Nadu"
],
"metrics": [
{
"values": [
"4",
"4",
"4",
"0",
"111",
"5100.0",
"111",
"0",
"0.0"
]
}
]
},
{
"dimensions": [
"20200316",
"(not set)",
"India",
"Chrome",
"desktop",
"(direct) / (none)",
"(not set)",
"Tamil Nadu"
],
"metrics": [
{
"values": [
"1",
"1",
"0",
"0",
"6",
"266.0",
"6",
"0",
"0.0"
]
}
]
},
{
"dimensions": [
"20200318",
"(not set)",
"India",
"Chrome",
"desktop",
"(direct) / (none)",
"(not set)",
"Tamil Nadu"
],
"metrics": [
{
"values": [
"1",
"2",
"0",
"0",
"20",
"135.0",
"20",
"0",
"0.0"
]
}
]
}
],
"totals": [
{
"values": [
"6",
"7",
"4",
"0",
"137",
"5501.0",
"137",
"0",
"0.0"
]
}
],
"rowCount": 3,
"minimums": [
{
"values": [
"1",
"1",
"0",
"0",
"6",
"135.0",
"6",
"0",
"0.0"
]
}
],
"maximums": [
{
"values": [
"4",
"4",
"4",
"0",
"111",
"5100.0",
"111",
"0",
"0.0"
]
}
],
"isDataGolden": true
}
}
]
}
I Want to convert it and bring it in a form that the column header:dimensions and metric header entries name will become column names and their values,ie data.rows.dimensions and metrics.values become corresponding values
ga:date ga:campaign ga:country ga:browser ga:deviceCategory ga:sourceMedium ga:socialNetwork ga:region ga:users ga:sessions ga:newUsers : (column names)
20200316 (not set) India Chrome desktop (direct) / (none) (not set) Tamil Nadu 1 1 1 :(values)
If you can use an Integration account, I suggest to create a flat file schema with the desired structure, and in the logic app you can convert in xml and then apply the Flat File Encoding.
Otherwise a function app should resolve your issue

unable to extract value using ._find

I have the following node.js code where I want to extract the value "abc" chosen by user as a name. I get result as undefined when I run this code:
let input= [
{
"param": [
{
"id": "name",
"choice": [
{
"label": "abc",
"value": "abc",
"valueId": "abc"
}
]
},
{
"id": "alias",
"choice": [
{
"label": "dsf",
"value": "dsf",
"valueId": "dsf"
}
]
},
{
"id": "description",
"choice": [
{
"label": "",
"value": "",
"valueId": ""
}
]
},
{
"id": "Key",
"choice": [
{
"label": "K",
"value": "K",
"valueId": "K"
}
]
},
{
"id": "tagKey",
"choice": [
{
"label": "",
"value": "",
"valueId": ""
}
]
},
{
"id": "tagValue",
"choice": [
{
"label": "",
"value": "",
"valueId": ""
}
]
},
{
"id": "multiquantity",
"choice": [
{
"label": "1",
"valueId": "1",
"value": "1"
}
]
}
],
"old": [],
"current": null
}
]
let result = (_.find(input.param, {id: "name"})).choice[0].valueId;
console.log("value"+result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
Seems that the logic is not able to extract the correct value. I need the output as abc. please help

How to find count of children of root nodes json data in angularjs

I have the following array of JSON data. There are two root nodes and then there are subnodes of the root nodes and sub-nodes of sub-nodes. I need to find how many subnodes does the root node has. I have no idea how to do that.
[
{
"Id": "0",
"Name": "Subscriber"
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
"Events": [
{
"Id": "0",
"Name": "Subscriber"
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
},
{
"Id": "1",
"Name": "Suscriber 1"
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
},
{
"Id": "1",
"Name": "Subscriber"
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
},
{
"Id": "1",
"Name": "Suscriber 1"
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
}
],
"Actions": null
},
{
"Id": "1",
"Name": "Suscriber 1"
"Events": [
{
"Id": "0",
"Name": "Subscriber"
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
},
{
"Id": "1",
"Name": "Suscriber 1"
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
},
{
"Id": "1",
"Name": "Subscriber"
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
},
{
"Id": "1",
"Name": "Suscriber 1"
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
}
],
"Actions": null
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
},
{
"Id": "1",
"Name": "Subscriber"
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
"Events": [
{
"Id": "0",
"Name": "Subscriber"
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
},
{
"Id": "1",
"Name": "Suscriber 1"
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
},
{
"Id": "1",
"Name": "Subscriber"
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
},
{
"Id": "1",
"Name": "Suscriber 1"
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
}
],
"Actions": null
},
{
"Id": "1",
"Name": "Suscriber 1"
,
"Events": [
{
"Id": "0",
"Name": "Subscriber"
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
},
{
"Id": "1",
"Name": "Suscriber 1"
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
},
{
"Id": "1",
"Name": "Subscriber
"Suscribers": [
{
"Id": "0",
"Name": "Suscriber 1"
},
{
"Id": "1",
"Name": "Suscriber 1"
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
}
],
"Actions": null
}
],
"Actions": [
{
"Name": "Start",
"Text": "Abc"
},
{
"Name": "Start",
"Text": "Abc"
}
]
}
]