Angular2, Typescript,Json - json

I am going to use angular2 platform to develop an application. I am stuck at one point that "How do I print nested json in Angular2 Component's template".
json file:
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": "0000.55",
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}
It's greatful if someone help me....:)

Try something like this:
<div *ngFor="let obj of jsonData">
<div>{{obj.id}}</div>
...
<div *ngFor="let bat of obj.batters.batter">
<div>{{bat.id}}</div>
<div>{{bat.type}}</div>
</div>
<div *ngFor="let topp of obj.topping">
<div>{{topp.id}}</div>
<div>{{topp.type}}</div>
</div>
</div>
You can change your object:
...,
"batters": [
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
],
...
then you can do like this:
<div *ngFor="let bat of obj.batters">
Hope this will help.

Related

Azure Function App new JSON with only a few properties

I am struggling of finding a feasible solution for my Azure Logic App.
A HTTP Request-action call will list the virtual networks of an Azure subscription.
The response look somehow like this:
{
"value": [
{
"name": "virtualNetworkName1",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName1/providers/Microsoft.Network/virtualNetworks/virtualNetworkName1",
"etag": "W/\"11111-1111-111\"",
"type": "Microsoft.Network/virtualNetworks",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "111-1111-11111",
"addressSpace": {
"addressPrefixes": [
"192.168.0.0/25"
]
}
}
},
{
"name": "virtualNetworkName2",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName2/providers/Microsoft.Network/virtualNetworks/virtualNetworkName2",
"etag": "W/\"22222-2222-222\"",
"type": "Microsoft.Network/virtualNetworks",
"location": "westeurope",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "222-2222-22222",
"addressSpace": {
"addressPrefixes": [
"192.168.1.0/24"
]
}
}
}
]
}
The resonse has even more properties which aren't necessary.
Regarding to this, I would like to use the HTTP Response-action in a JSON format with only a few properties:
Name
Id
Location
Like this:
[
{
"name": "virtualNetworkName1",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName1/providers/Microsoft.Network/virtualNetworks/virtualNetworkName1",
"location": "eastus"
},
{
"name": "virtualNetworkName2",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName2/providers/Microsoft.Network/virtualNetworks/virtualNetworkName2",
"location": "westeurope"
}
]
Is it possible to realize it with only Logic App native actions?
I have reproduced in my environment and got expected results as below:
Firstly, I have initialized your output in a variable and then used parse Json and compose to get required output:
Parse Json Schema:
{
"properties": {
"value": {
"items": {
"properties": {
"id": {
"type": "string"
},
"location": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
Output:
First json Output:
Second one:
Code view of Logic app:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": {
"value": [
{
"etag": "W/\"11111-1111-111\"",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName1/providers/Microsoft.Network/virtualNetworks/virtualNetworkName1",
"location": "eastus",
"name": "virtualNetworkName1",
"properties": {
"addressSpace": {
"addressPrefixes": [
"192.168.0.0/25"
]
},
"provisioningState": "Succeeded",
"resourceGuid": "111-1111-11111"
},
"type": "Microsoft.Network/virtualNetworks"
},
{
"etag": "W/\"22222-2222-222\"",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName2/providers/Microsoft.Network/virtualNetworks/virtualNetworkName2",
"location": "westeurope",
"name": "virtualNetworkName2",
"properties": {
"addressSpace": {
"addressPrefixes": [
"192.168.1.0/24"
]
},
"provisioningState": "Succeeded",
"resourceGuid": "222-2222-22222"
},
"type": "Microsoft.Network/virtualNetworks"
}
]
},
"runAfter": {},
"type": "Compose"
},
"For_each": {
"actions": {
"Compose_2": {
"inputs": {
"id": "#items('For_each')?['id']",
"location": "#items('For_each')?['location']",
"name": "#items('For_each')?['name']"
},
"runAfter": {},
"type": "Compose"
}
},
"foreach": "#body('Parse_JSON')?['value']",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Foreach"
},
"Parse_JSON": {
"inputs": {
"content": "#outputs('Compose')",
"schema": {
"properties": {
"value": {
"items": {
"properties": {
"id": {
"type": "string"
},
"location": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
Now you will get required fields as I have got.

Extracting lines from nested json file using Ubuntu

I have nested json file (each field can have one or more sons) with many lines. Something like this:
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}
Using Ubuntu (or Unix) I would like to find the first 10 lines that their "batters" field is not empty (i.e. in the line one or more of its sons contain value (not null or "").

How to flatten two json arrays using apache drill

{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}
I have the above json and i want to flatten both batter and topping arrays.
so i tried doing:
SELECT flatten(topping) as toping,flatten(batters.batter) as bat FROM json.jsonfiles.`batter.json`;
which gives me
org.apache.drill.common.exceptions.UserRemoteException: VALIDATION
ERROR: From line 1, column 43 to line 1, column 49: Table 'batters'
not found SQL Query null [Error Id:
33cf80f2-f283-4401-90ce-c262474e0778 on acer:31010]
How can i solve this? Can we flatten two arrays in a single query?
You need to add table alias and refer it in columns. Below query works for me with sample data you have provided.
SELECT flatten(a.topping) as toping,flatten(a.batters.batter) as bat FROM dfs.tmp.`batter.json` a;

Error creating JSON Unexpected Character Sequence

I've been trying to create a basic json for our testes to throw up a machine a and when required. I got most of it done however I am getting the following errors:
Line 158 Unexpected character sequence in member name
Line 167 A member with the name 'Properties' already exists
I understand 67 needs to be unique, but everytime I change and remove the { it creates more errors.
And unexpected character is the { on line 157, which I'm guessing should be either a string, maybe?
My template is below.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"offer": {
"type": "string",
"defaultvalue": "Windows",
"allowedValues": [
"windows",
"centos",
"RHEL"
]
},
"sku": {
"type": "string",
"defaultvalue": "2012-r2-datacenter",
"allowedValues": [
"2012-R2-Datacenter",
"2012-R2",
"68",
"72",
"73",
"74"
]
},
"virtualMachineSize": {
"type": "string",
"defaultvalue": "standard_A0",
"allowedValues": [
"Standard_A0",
"Standard_A1",
"standard_A2"
]
},
"adminUsername": {
"type": "string"
},
"ipaddress": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"storageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountId": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"ContainerName": {
"type": "string"
},
"autoShutdownStatus": {
"type": "string"
},
"autoShutdownTime": {
"type": "string"
},
"autoShutdownTimeZone": {
"type": "string"
},
"autoShutdownNotificationStatus": {
"type": "string"
}
},
"variables": {
"vnetId": "[resourceId('avset','Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
"stdvhdcontainername": "[concat(parameters('Containername'))]",
"vmosidiskname": "[concat(parameters('virtualMachineName'),'-osdisk')]"
},
"resources": [
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2016-04-30-preview",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat (parameters('diagnosticsStorageAccountName')), ['blob']]"
}
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"offer": "[concat(parameters('offer'))]",
"sku": "[concat(parameters('offer'))]",
"version": "latest"
}
},
"osDisk": {
"vhd": {
"name": "[variables('vmosidiskname')]",
"uri": "[concat('http://', parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdvhdcontainername'),'/', variables('vmosidiskname'), '.vhd')]"
},
"name": "[parameters('virtualMachineName')]"
},
"name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
"type": "Microsoft.DevTestLab/schedules",
"apiVersion": "2017-04-26-preview",
"location": "[parameters('location')]",
"properties": {
"status": "[parameters('autoShutdownStatus')]",
"taskType": "ComputeVmShutdownTask",
"dailyRecurrence": {
"time": "[parameters('autoShutdownTime')]"
},
"timeZoneId": "[parameters('autoShutdownTimeZone')]",
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
"notificationSettings": {
"status": "[parameters('autoShutdownNotificationStatus')]",
"timeInMinutes": "30"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
]
},
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2016-09-01",
"location": "[parameters('location')]"
},
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateipaddress": "[concat(parameters('ipaddress'))]",
"privateIPAllocationMethod": "static"
}
}
]
}
},
"outputs": [
{
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
]
}
]
}
Any pointers would be greatly appreciated.. thanks for your help :)
Params are below:)
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"value": "westeurope"
},
"virtualMachineName": {
"value": "cent-os-vm2"
},
"virtualMachineSize": {
"value": "Standard_A0"
},
"adminUsername": {
"value": "localadmin"
},
"virtualNetworkName": {
"value": "avset-vnet"
},
"networkInterfaceName": {
"value": "cent-os-vm01652"
},
"networkSecurityGroupName": {
"value": "cent-os-vm01-nsg"
},
"storageAccountName": {
"value": "avsetdisks419"
},
"diagnosticsStorageAccountName": {
"value": "avsetdiag112"
},
"diagnosticsStorageAccountId": {
"value": "avsetdiag117"
},
"subnetName": {
"value": "default"
},
"autoShutdownStatus": {
"value": "Enabled"
},
"autoShutdownTime": {
"value": "19:00"
},
"autoShutdownTimeZone": {
"value": "UTC"
},
"autoShutdownNotificationStatus": {
"value": "Disabled"
},
"ContainerName": {
"value": "vhd"
},
"offer": {
"value": "windows"
},
"sku": {
"value": "2012-R2-Datacenter"
},
"ipaddress": {
"value": "10.0.1.9"
}
}
}
There are many mistakes in your template. The following template should work.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"offer": {
"type": "string",
"defaultvalue": "windows",
"allowedValues": [
"windows",
"centos",
"RHEL"
]
},
"sku": {
"type": "string",
"defaultvalue": "2012-R2-Datacenter",
"allowedValues": [
"2012-R2-Datacenter",
"2012-R2",
"68",
"72",
"73",
"74"
]
},
"virtualMachineSize": {
"type": "string",
"defaultvalue": "Standard_A0",
"allowedValues": [
"Standard_A0",
"Standard_A1",
"standard_A2"
]
},
"adminUsername": {
"type": "string"
},
"ipaddress": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"storageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountId": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"ContainerName": {
"type": "string"
},
"autoShutdownStatus": {
"type": "string"
},
"autoShutdownTime": {
"type": "string"
},
"autoShutdownTimeZone": {
"type": "string"
},
"autoShutdownNotificationStatus": {
"type": "string"
}
},
"variables": {
"vnetId": "[resourceId('avset','Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
"stdvhdcontainername": "[concat(parameters('Containername'))]",
"vmosidiskname": "[concat(parameters('virtualMachineName'),'-osdisk')]"
},
"resources": [
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2016-04-30-preview",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat (parameters('diagnosticsStorageAccountName')), ['blob']]"
}
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"offer": "[concat(parameters('offer'))]",
"sku": "[concat(parameters('offer'))]",
"version": "latest"
}
},
"osDisk": {
"vhd": {
"name": "[variables('vmosidiskname')]",
"uri": "[concat('http://', parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdvhdcontainername'),'/', variables('vmosidiskname'), '.vhd')]"
},
"name": "[parameters('virtualMachineName')]"
}
}
},
{
"name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
"type": "Microsoft.DevTestLab/schedules",
"apiVersion": "2017-04-26-preview",
"location": "[parameters('location')]",
"properties": {
"status": "[parameters('autoShutdownStatus')]",
"taskType": "ComputeVmShutdownTask",
"dailyRecurrence": {
"time": "[parameters('autoShutdownTime')]"
},
"timeZoneId": "[parameters('autoShutdownTimeZone')]",
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
"notificationSettings": {
"status": "[parameters('autoShutdownNotificationStatus')]",
"timeInMinutes": "30"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
]
}
},
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2016-09-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateipaddress": "[concat(parameters('ipaddress'))]",
"privateIPAllocationMethod": "static"
}
}
]
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
In line 162, it lost a ,. Resource Microsoft.Compute/virtualMachines,Microsoft.DevTestLab/schedules,Microsoft.Network/networkInterfaces are in parallel. But in your template, Microsoft.Compute/virtualMachines contains others, so you get error log with the name 'Properties' already exists.
Note: You also need check your default value. Please note that case sensitive.
Update:
Ipconfigurations is wrong, it should like below:
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
Update 2:
The template.json and parameters.json works for me. Maybe you could modify your template according to this example.

how to create a angular table row to have a collapsed row

I have a table which will have collapsed rows that have 2nd level info, but not all the rows will have this 2nd level data.
How can i write a controller to only show a 2nd level collapse row if the JSON script has a 2nd level?
With the following json defined in your controller:
$scope.cakes = [{ "id": "0001", "type": "donut", "name": "Cake",
"ppu": 0.55, "batters": "whatever",
"topping": [ { "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" } ] },
{ "id": "0002", "type": "cupcake", "name": "Cupcake",
"ppu": 0.60, "batters": "whatever",
"topping": [] },
{ "id": "0003", "type": "muffin", "name": "Muffin",
"ppu": 0.25, "batters": "whatever",
"topping": [] }
];
you can selectively show a second row in a table where cake.topping.length is greater than 0:
<table>
<tr ng-repeat-start="cake in cakes">
<td>{{cake.type}}</td><td>{{cake.name}}</td>
</tr>
<tr ng-repeat-end ng-show="cake.topping.length>0">
<td ng-repeat="t in cake.topping">{{t.type}}</td>
</tr>
</table>