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.
Related
I'm having an issue extracting data from IOT Hub to Azure Stream Analytics to Power BI.
Here is the data coming from Stream Analytics:
{
"header":{
"version":1
},
"data":{
"treatmentId":"1",
"machineData":[
{
"recordId":3,
"records":[
{
"fields":[
{
"value":"+182",
"key":"VP"
}
],
"group":"PR"
}
]
}
]
},
"EventProcessedUtcTime":"2018-12-05T16:52:43.6450807Z",
"PartitionId":0,
"EventEnqueuedUtcTime":"2018-12-05T16:38:47.1900000Z",
"IoTHub":{
"CorrelationId":null
}
}
Using the following query:
SELECT *
INTO DataPowerBI
FROM iothub;
I am getting the following output in PowerBI:
I am not able to get the child level data under "data", like treatment id, machine data, groups, keys. Can I get a query for pushing all levels of the data, both parent and children?
Thanks in advance!
Raj
By using select *, you only get the upper level data-fields back. If you want the data that is nested, you need to specify the data you want.
select data.treatmentid will get you the treatmentId
I am not sure how it works with nesting within nesting. You could try
select data.machinedata.recordId to get the recordId.
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"
}
]
}
I'm trying to populate a table with the output of several API sources having extracted several identical variables from each source. So far I have most of the pieces I need worked out, such as how to retrieve the data, create the table and import the data in order to create the table using an existing framework. What I don't have is a means of formatting the API data to meet the framework's requirement such as..
Required format:
[
{id:1, name:"Billy Bob", age:"12", gender:"male", height:1, col:"red", dob:"", cheese:1},
{id:2, name:"Mary May", age:"1", gender:"female", height:2, col:"blue", dob:"14/05/1982", cheese:true},
{id:3, name:"Christine Lobowski", age:"42", height:0, col:"green", dob:"22/05/1982", cheese:"true"},
]
Create a table from the formatted data...
<div id="example-table"></div>
$("#example-table").tablear({
columns:[
{title:"Name", field:"name"},
{title:"Age", field:"age"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height"},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob"},
{title:"Cheese Preference", field:"cheese"},
],
});
Whenever you get json as response you need to parse the json and then play with that.
Example:
if(response)
{
var myObj = parse.JSON(response) // this will give you the javascript
//object
}
There is also another option of using jquery datatable using server side processing. This automatically creates a table for you.
Jquery Datatable
I am going to implement the REST base CRUD modal in my my app.I wan to display the list of product data with edit and delete link
Product
id, title, unit_id, product_type_id, currency_id,price
Q1: what should be json response look like?
There are two formats comes in my mind to place the data in Json as a response of REST Get call
[
{
id:1,
title:"T-Shirt",
unit_id:20,
unit_title: "abc"
product_type_id:30,
product_type_title:"xyz"
currency_id: 10,
currency_name: "USD"
min_price:20
},
{...}
]
and the another one is
[
{
id:1,
title:"T-Shirt",
unit: {
id: 20,
title: "abc"
},
product_type: {
id: 30,
title: "xyz"
},
currency_id: {
id:10,
name: "USD"
},
min_price:20
},
{...}
]
what is the better and standard way to handle the above scenario?
Furthermore, let suppose I have 10 more properties in product table which will never display on list page. but i needed it when user going to edit the specific item.
Q2: Should I the load all data once at the time of displaying product list and pass the data to edit component.
or
Load only the needed propeties of product table and pass the id to produt edit component and a new REST GET call with id to get the properties of product.
I am using React + Redux for my front end
Typically, you would create additional methods for API consumers to retrieve the values that populate the lists of currency, product_type and unit when editing in a UI.
I wouldn't return more data than necessary for an individual Product object.
Im trying to create a d3.js graph from a rails database. This takes the following json
{
"nodes":[
{
"name":"Sebo",
"group":4,
"id":1
},
{
"name":"Pierre",
"group":5,
"id":2
},
{
"name":"Bilbo",
"group":2,
"id":3
},
{
"name":"yyyyyyyy",
"group":2,
"id":4
}
],
"links":[
{
"source":3,
"target":2,
"value":null
},
{
"source":3,
"target":1,
"value":null
},
{
"source":4,
"target":2,
"value":null
},
{
"source":4,
"target":1,
"value":null
}
]
}
I have created a button that allows a current user to follow another user. This then gets stored in a database and eventually the graph can be re-visualised.
The problem is that the request to update the database is based on the current user id (from the database). This is a non-zero based indexing so the first user is user id:1. However the json uses zero based indexing. This means that if user_id=1 connects to user_id=4 then when the graph is seen again this connection is attributed to user_id:2. What would be great is if I could specify that the user_id index could start with zero so that the array and database are in agreement. Is this the correct way to think about this? Can I force the indexing of the user table to start at zero eg in a rails schema?