Read Json dymaic elements values in unix - json

Need help to read a Json dynamic json data unix
{
"Dept1":{
"Emp1":{
"Name":"D1E1xyz"
"Salary":"1234"
},
"Emp2":{
"Name":"D1E2ABCD"
"Salary":"9867"
}
}
}
{
"Dept2":{
"Emp1":{
"Name":"D2E1xyz"
"Salary":"1234"
},
"Emp2":{
"Name":"D2E2ABCD"
"Salary":"9867"
},
"Emp3":{
"Name":"D2E3PQRS"
"Salary":"9867"
},
}
I'm trying to print using unix commands , have tried couple but stil no luck .. did anyone come across similar case , Please help with code sniper
dept1,1234,9867
dept2,1234,9867,9867

Related

Secomea DCM 3529 multiple triggers or two values in the same reading

I am currently having troubles with Secomea Data Collection Module, I was wondering if anyone here might be able to enlighten me.
So I am collecting sensor data from the product Secomea 3529 through a portal called Secomea Sitemanager. I can't seem to find any information about my two questions below, I hope someone knows the answer.
Information about protocol used in this project
"Protocol": "S7/TCP",
"S7Access": {
"S7Model": "S7-200",
"S7Rack": 0,
"S7Slot": 1
When collecting data it is programmed using JSON as seen below.
I was wondering if it is possible to somehow have more than one TriggerSample and if so how is it set up?
{
"SampleName": "Sensor1",
"SampleDescription": "Some Description",
"SampleDataType": "bool",
"SamplesSaved": 3600,
"Aggregation": {
"Function": "compute",
"Expression": "Sensor2,1,/",
"TriggerSample": "Sensor3"
}
},
My other question, is it possible to have more than one S7Var?
{
"SampleName": "ModeCheck",
"SampleDescription": "Mode status",
"SampleDataType": "int16",
"SamplesSaved": 360,
"S7Var": {
"S7PLCVar": "LocationInMachineDB1",
"S7SampleInterval": 5
}
},

How to access Parent Element from json object using Vuejs

I'm very new at Vue.js and i'm trying to access a data from an api. I got some JSON data and i want to access my sensors id's. But sensor id's doesn't have any name. For example, this is my data:
{
"SID":"valid"
}{
"alarms":1598532382,
"chanscan":1,
"cloud_config":1579015363,
"cloud_credentials":1,
"cloud_status":1,
"currData":1598532382,
"favourites":1579015363,
"hardware":1597737383,
"oldestRecords":1,
"scanreq":1,
"sensors_raw":1598270610,
"settings_raw":1597740959,
"users":1597740912
}1598532408{
"1053397":{
"time":1598531818,
"t":30.15,
"h":42,
"lost":0,
"rssi":-67,
"volt":1.48,
"ptype":6,
"grey":0,
"vari":9
},
"3146177":{
"time":1598532123,
"t":30.15,
"h":43,
"p":100070,
"co2":609,
"co2Abc":0,
"lost":0,
"rssi":-58,
"volt":1.56,
"ptype":13,
"grey":0,
"vari":16
},
"4195593":{
"time":1598107788,
"C":103,
"lost":0,
"rssi":-71,
"volt":3.06,
"ptype":13,
"vari":2,
"t":null,
"h":null,
"p":null,
"co2":null,
"co2Abc":null
},
"6292226":{
"time":1598532029,
"t":25.7,
"bec":0.0247,
"pec":0.961,
"dp":5.555887,
"vwc":0.093,
"lost":0,
"rssi":-62,
"volt":1.44,
"ptype":20,
"grey":0,
"vari":1
},
"lastRx":1598532123,
"missing":1,
"paired":4
}{
"1053397":{
"humi":{
"type":"humi",
"since":1598346415,
"desc":"threshumiover",
"value":42,
"diff":12
}
},
"4195593":{
"rssi":{
"type":"fatal",
"desc":"packetslost",
"since":1598107786
}
}
}
What can I do to access the "1598532408", "3146177" and "1053397" values so I can display them in the left column of a table? Example of my vue.js table:
<tr v-for="sensor in list" v-bind:key="sensor">
<td>{{sensor}}</td>
<td>{{sensor.time}}</td>
</tr>
Using {{sensor}} gives me all of my data.
Any help would be tremendously appreciated here. I'll have to redo some of this once they actually get the data right, but for now, this is sort of what I'm working with.

Convert array of hash by logstash to simple hash

I am trying to parse by logstash this:
"attributes": [
{
"value": "ValueA",
"name": "NameA"
},
{
"value": "ValueB",
"name": "NameB"
},
{
"value": "ValueC",
"name": "NameC"
}
],
To this:
"attributes": {
"NameA": "ValueA",
"NameB": "ValueB",
"NameC": "ValueC"
}
Any recommendations?
I don't want to split this list to more records...
I have found th solution. For anyone dealing with a similar problem, here is the solution and a short story...
In the beginning, I tried this:
ruby {
code => '
xx = event.get("[path][to][data_source]")
event.set(['_my_destination'], Hash[xx.collect { |p| [p[:name], p[:value]] }])
'
But it returned an error because of the set method allowing a string only.
So I tried to do it this way:
ruby {
code => '
event.get("[path][to][data_source]").each do |item|
k = item[:name]
event.set("[_my_destination][#{k}]", item[:value])
end
'
}
I spent a lot of time debugging it because it works everywhere except in logstash :-D. After some grumbling, I finally fixed it. The solution with commentary is as follows.
ruby {
code => '
i = 0 # need index to address hash in array
event.get("[json_msg][mail][headers]").each do |item|
# need to use event.get function to get value
k = event.get("[json_msg][mail][headers][#{i}][name]")
v = event.get("[json_msg][mail][headers][#{i}][value]")
# now it is simple
event.set("[json_msg][headers][#{k}]", v)
i += 1
end
'
}
I think you should be able to do it with a custom Ruby script - see the ruby filter. You'll use the Event API to manipulate the event.
Maybe the aggregate filter could be also used but the Ruby script with one for loop seems more straightforward to me.

Extracting multiple associative objects from JSON type in MySQL

Trying to figure out the best way to query a MySQL table containing a json column.
I am successfully able to get product OR port.
SELECT ip, JSON_EXTRACT(json_data, '$.data[*].product' ) FROM `network`
This will return:
["ftp","ssh"]
What I'm looking to get is something like this, or some other way to represent association and handle null values:
[["ftp",21],["ssh",22],[NULL,23]]
Sample JSON
{
"key1":"Value",
"key2":"Value",
"key3":"Value",
"data": [
{
"product":"ftp",
"port":"21"
},
{
"product":"ssh",
"port":"22"
},
{
"port":"23"
}
]
}

Azure Stream Analytics Querying JSON

I have a problem writing a query to extract a table out of the arrays from a json file: The problem is how to get the information of the array “clientPerformance” and then make them all in a normal sql table.
The file looks like this:
"clientPerformance":[
{
"name":"opportunity",
"clientProcess":{
"value":3620000.0,
"count":1.0,
"min":3620000.0,
"max":3620000.0,
"stdDev":0.0,
"sampledValue":3620000.0
},
"networkConnection":{
"value":10000.0,
"count":1.0,
"min":10000.0,
"max":10000.0,
"stdDev":0.0,
"sampledValue":10000.0
},
"receiveRequest":{
"value":9470000.0,
"count":1.0,
"min":9470000.0,
"max":9470000.0,
"stdDev":0.0,
"sampledValue":9470000.0
},
"sendRequest":{
"value":1400000.0,
"count":1.0,
"min":1400000.0,
"max":1400000.0,
"stdDev":0.0,
"sampledValue":1400000.0
},
"total":{
"value":14500000.0,
"count":1.0,
"min":14500000.0,
"max":14500000.0,
"stdDev":0.0,
"sampledValue":14500000.0
},
"url":"https://xxxx",
"urlData":{
"base":"/main.aspx",
"host":"xxxx",
"hashTag":"",
"protocol":"https"
}
}
]
I tried to use Get array elements method and other ways but I am never able to access to clientProcess, networkConnection.. elements
I tried to use for exampls this one:
Select
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 0), 'name') AS Name,
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 1), 'clientProcess.count') AS clientProcessCount,
FROM [app-insights-blob-dev] Input
I would appreciate any help :)
I slightly edited your query to return the clientProcessCount.
(I changed the array index from 1 to 0). Also make sure your JSON object starts with { and ends with }.
Select
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 0), 'name') AS Name,
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 0), 'clientProcess.count') AS clientProcessCount
FROM [app-insights-blob-dev] Input
For other examples to query complex objects with ASA, don't hesitate to look at this blog post.