Nested Array extract from JSON with VBA EXCEL - json

I'm trying to extract data from a nested array in a JSON file, but I don't manage to get these. In this example, I want to get the IDs.
"order-lines": [
{
"id": 12610
},
{
"id": 12611
}
],
For now I'm using this code but it doesn't work.
Set Json = ParseJson(oRequest.responseText)
For Each Item In Json
Cells(i, 4).Value = Item("order-lines")(1)("id")
Next
Can you please help me?
Thank you in advance

Related

Parse multi level JSON with Ruby

I am trying to parse the JSON file below. The problem is I cannot return "Mountpoint" as a key. It only gets parsed as a value. This is the command I am using to parse it json_data = JSON.parse(readjson). The reason I guess that it's a key is because if I run json_data.keys only EncryptionStatus and SwitchName are returned. Any help would be greatly appreciated.
{
"EncryptionStatus": [
{
"MountPoint": "C:",
"VolumeStatus": "FullyEncrypted"
},
{
"MountPoint": "F:",
"VolumeStatus": "FullyEncrypted"
},
{
"MountPoint": "G:",
"VolumeStatus": "FullyEncrypted"
},
{
"MountPoint": "H:",
"VolumeStatus": "FullyEncrypted"
}
],
"SwitchName": [
"LAN",
"WAN"
]
}
I tried using dig as a part of my JSON.parse but that didn't seem to help me.
JSON data can have multiple levels.
Your JSON document is a
Hash (Dictionary/Map/Object in other languages) that has two keys ("EncryptionStatus", "SwitchName"),
The value for the "EncryptionStatsu" key is an Array of Hashes (with keys "MountPoint" and "VolumeStatus").
# assuming your JSON is in a file called "input.json"
data = File.read("input.json")
json = JSON.parse(data)
json["EncryptionStatus"].each do |encryption_status|
puts "#{encryption_status["MountPoint"]} is #{encryption_status["VolumeStatus"]}"
end
This will print out
C: is FullyEncrypted
F: is FullyEncrypted
G: is FullyEncrypted
H: is FullyEncrypted
If you want to access a specific item you can look at the dig method. E.g.
json.dig("EncryptionStatus", 3)
Would return the information for mountpoint "H"

Retreive specific data inside json body as list in django

In purpose to delete multiple data using function
Product.objects.in_bulk([pk1,pk2,pk3,...]).delete()
I'm trying to grab pk value from json as list for in_bulk function param.
my json :
[
{
"Pk": 1,
"Product": "testing"
},
{
"Pk": 2,
"Product": "testing"
}
]
But i don't know how to achieve this in django (i'm new in django from .NET backgroud). Should i iterate each object in json in order to get each pk or there's smartest way to get list pk value ?
You delete this with:
Product.objects.filter(pk__in=list_of_pks).delete()
So if you have a JSON blob, you can work with:
from json import loads as jloads
my_json_blob = '[ {"Pk": 1, …}, … ]'
data = jloads(my_json_blob)
Product.objects.filter(pk__in=[d['Pk'] for d in data]).delete()

Parse JSON value into separate strings in telegraf.conf

I am using telegraf inputs.tail to parse my application log files. Input data is in json format like so:
{
"key1":"value1",
"key2":"value2",
"key3":"value3a^value3b"
}
Question - How to parse the value of key3 so that I can write value3a and value3b to two separate tags/columns in influxDB?
telegraf.conf snippet:
[[inputs.tail]]
files = ["/path/to/log/server.log"]
data_format = "json"
tag_keys = [
"key1",
"key2",
"key3"
]
Been breaking my head with this problem for 2 days now. Any help would be much appreciated!
Thanks in advance.

Object required: '[undefined]' error when looping through JSON data

I am working with the Google Translation API, which returns results in JSON format - e.g.
{
"data": {
"translations": [
{
"translatedText": "Hola mundo"
},
{
"translatedText": "Te amo"
},
{
"translatedText": "queso"
}
]
}
}
I am trying to parse the JSON data using Classic ASP.
I'm using ASPJSON (http://www.aspjson.com/) to parse the JSON data.
I can get so far with reading the data - e.g. (where "BackFromGoogle") is the objXML.responseText from a MSXML2.ServerXMLHTTP call.
Set oJSON = New aspJSON
oJSON.loadJSON(BackFromGoogle)
For Each translation In oJSON.data("data") 'iterate through data
Set this = oJSON.data("data").item(translation)
Next
If I then try:
For Each translation In oJSON.data("data") 'iterate through data
Set this = oJSON.data("data").item(translation)
Response.Write this.item("translations").item("translatedText")
Next
Then I get this error:
Microsoft VBScript runtime error '800a01a8'
Object required: '[undefined]'
For this line:
Response.Write this.item("translations").item("translatedText")
I am very stuck working out the syntax to allow me to access the individual values of the "translatedText" lines.
Is it possible to access them?
Got this working in the end.
Found the answer via the solution here:
VbScript Deserialize JSON
This sorted it:
Set oJSON = New aspJSON
oJSON.loadJSON(BackFromGoogle)
For Each result In oJSON.data("data")("translations")
Set this = oJSON.data("data")("translations").item(result)
response.Write this.item("translatedText") & "<br>"
Next

Json Array from spring Blank in the table using angularJS

i have json array from spring rest like this:
var v=[{"id":"A1",
"name":"Bobi",
"age":27,
"supervisor":{
"id":"S1",
"name":"Doni",
"age":27,
"supervisor":null
}
},
{
"id":"B1",
"name":"Thomas",
"age":27,
"supervisor":{
"id":"C1",
"name":"Ronald",
"age":27
"supervisor":null
}
},
"C1",
"S1"
]
i want to show it in the table using angularJS, but in 3rd and 4th row always blank.
How i can show "C1" and "S1" ?
Though your JSON is valid but C1 & S1 are not in the same format as A1 & B1.
So, if you want to show all values in the same table in same format, then the JSON should also have to be of the same format.
Having them in the same format in API is far much easier then formatting the JSON in angular and making it work like the other objects.
Hope this helps.