I have Json --
[
{
"label": "EL04_AA02_P2064_12588",
"uri": "http://www.awer.com/onasdgfgies/addhh.rdf#i613b844f9b503172424717ebbfa5f73098",
"updated_at": "2022-07-27 09:16:43",
"interactionData": [
{
"type": "Choice",
"nb choice": 4,
"responseIdentifier": "RESPONSE_A",
"BR_identifier": "choice_2",
"BR_label": "chronological order",
"choice_identifier_1": "choice_1",
"choice_label_1": "problem and solution",
"choice_identifier_2": "choice_2",
"choice_label_2": "chronological order",
"choice_identifier_3": "choice_3",
"choice_label_3": "cause and effect ",
"choice_identifier_4": "choice_4",
"choice_label_4": "comparison of ideas"
},
{
"type": "Choice",
"nb choice": 6,
"responseIdentifier": "RESPONSE_B",
"BR_identifier": "choice_8|choice_13",
"BR_label": "“In 1958, asdghfjgjjk asdghfjgjjk became NASA. Shortly thereafter, asdghfjgjjk became part of the space team.” (paragraph 7)|“In September 1962, President John F. Kennedy charged the country to send a man to the Moon.” (paragraph 8)",
"choice_identifier_1": "choice_5",
"choice_label_1": "“asdghfjgjjk was an asdghfjgjjk asdghfjgjjk who worked for asdghfjgjjk from 1953 until 1986.” (paragraph 1)",
"choice_identifier_2": "choice_6",
"choice_label_2": "“asdghfjgjjk was the name of the asdghfjgjjk agency that later became asdghfjgjjk.” (paragraph 4)",
"choice_identifier_3": "choice_7",
"choice_label_3": "“asdghfjgjjk.” (paragraph 5)",
"choice_identifier_4": "choice_8",
"choice_label_4": "“In 1958, asdghfjgjjk asdghfjgjjk became asdghfjgjjk. Shortly thereafter, asdghfjgjjk became part of the space team.” (paragraph 7)",
"choice_identifier_5": "choice_13",
"choice_label_5": "“asdghfjgjjk.” (paragraph 8)",
"choice_identifier_6": "choice_14",
"choice_label_6": "“to orbit.” (paragraph 8)"
}
],
"Task Model": "4B.1: Analyzing the relationship between a series of concepts",
"Common Core State Standard ID": "RI.4.5 4.1 Refer to d.",
"Evidence Statement": "RI 4.1.1: .",
"ELA Item Key": "",
"Number of Points": "2",
"Scoring Rules": "EBSR - 1A,2+E",
"Item Type": "EBSR",
"Task Type": "RST",
"Text Complexity": "Medium",
"CC4 Processing Demands": "Medium",
"CC3 Response Mode": "High",
"CC2 Command of Textual Evidence": "Medium",
"EOY Informational Category": "Reading Informational Text",
"Claim/Sub-Claim": "Reading - Informational Text",
"Item Set Sequence": "3",
"Item Passage Sequence": "",
"Associated Passage": "Who Was asdghfjgjjk",
"Passage Group": "asdghfjgjjk",
"Passage Set ID": "P2064",
"Grade": "Grade 4",
"Status Comments": "",
"Original UIN": "EL04_AA02_P2064_12588",
"Interaction Type IL": "",
"Operational": "",
"Field Test": "",
"Workflow Status": "09. Ready for Committee Review",
"Phases": "Year 2",
"Item Key": "B|D,E",
"5-Digit UIN": "12588",
"Item_Writer_ID": "CAE04",
"Multimedia": "No",
"Release Year": "",
"Scoring Rubric or Rationale": "B|D,E",
"Dependent Item": "",
"Scoring Mode": "",
"Alt Files": "",
"Exclude Accessibility Support Features": "",
"Accessibility Support Features": "",
"Item Enemy": "",
"Art": "",
"Delivery Mode": "Paper|Computer",
"Cognitive Complexity": "Medium",
"Bank": "Illinois",
"Subject": "ELA",
"Asset Type": "Item",
"State": "",
"assets": [
{
"Label": "EL04_AA02_RST_P2064-0_Scenario",
"Asset_Developer_ID": "",
"Original UIN": "",
"Content Type": "",
"Grade": "",
"Graphics/Multimedia Revisions Requested": "",
"Graphic_Alt_Tags": "",
"Academic Course": [],
"Passage/Stimulus Set ID": "",
"Paired Passage/Stimulus": "",
"Passage/Stimulus Set Title": "",
"Passage/Stimulus Set Sequence": "",
"Asset Workflow Status": "",
"Passage/Stimulus A Title": "",
"Passage/Stimulus A ID": "",
"Item Passage/Stimulus Sequence": [],
"Passage/Stimulus B Title": "",
"Phases": "",
"Passage/Stimulus B ID": "",
"Passage/Stimulus C Title": "",
"Passage/Stimulus C ID": "",
"Passage Type": "",
"Author Name": "",
"EOY Informational Category": "",
"Genre": [],
"Length Designation": "",
"Text Complexity Analysis": "",
"Word Count": "",
"Lexile": "",
"Flesch-Kincaid": "",
"RMM": "",
"Glossed Terms": "",
"Gender Representation in Text": "",
"Multi-Cultural Passage": "",
"Author Gender": "",
"Text Selection": "",
"Number of Art Pieces": "",
"Text Complexity": "",
"Task Type": "",
"Copyright": "",
"Delivery Mode": [],
"Copyright Type": "",
"Art": "",
"CCC Number": "",
"Source": "",
"Copyright Source Text": "",
"Rights": [],
"Text Permissions Notes": "",
"Art Permissions": "",
"State": "",
"PkgHref": "",
"PkgIdentifier": "",
"Language": "English",
"Alternative Text": "EL04_AA02_RST_P2064-0_Scenario",
"uri": "http://www.awer.com/onasdgfgies/addhh.rdf#i613b844f9b503172424717ebbfa5f73098",
"identifier": "i61af6b75e5c4c14293c665e5dc1199871a",
"updated_at": "2022-03-30 07:02:29"
},
{
"Label": "EL04_AA02_RST_P2064-1_WhoWasKatherineasdghfjgjjk",
"Asset_Developer_ID": "",
"Original UIN": "",
"Content Type": "",
"Grade": "",
"Graphics/Multimedia Revisions Requested": "",
"Graphic_Alt_Tags": "",
"Academic Course": [],
"Passage/Stimulus Set ID": "",
"Paired Passage/Stimulus": "",
"Passage/Stimulus Set Title": "",
"Passage/Stimulus Set Sequence": "",
"Asset Workflow Status": "",
"Passage/Stimulus A Title": "",
"Passage/Stimulus A ID": "",
"Item Passage/Stimulus Sequence": [],
"Passage/Stimulus B Title": "",
"Phases": "",
"Passage/Stimulus B ID": "",
"Passage/Stimulus C Title": "",
"Passage/Stimulus C ID": "",
"Passage Type": "",
"Author Name": "",
"EOY Informational Category": "",
"Genre": [],
"Length Designation": "",
"Text Complexity Analysis": "",
"Word Count": "",
"Lexile": "",
"Flesch-Kincaid": "",
"RMM": "",
"Glossed Terms": "",
"Gender Representation in Text": "",
"Multi-Cultural Passage": "",
"Author Gender": "",
"Text Selection": "",
"Number of Art Pieces": "",
"Text Complexity": "",
"Task Type": "",
"Copyright": "",
"Delivery Mode": [],
"Copyright Type": "",
"Art": "",
"CCC Number": "",
"Source": "",
"Copyright Source Text": "",
"Rights": [],
"Text Permissions Notes": "",
"Art Permissions": "",
"State": "",
"PkgHref": "",
"PkgIdentifier": "",
"Language": "English",
"Alternative Text": "EL04_AA02_RST_P2064-1_WhoWasKatherineasdghfjgjjk",
"uri": "http://www.awer.com/onasdgfgies/addhh.rdf#i613b844f9b503172424717ebbfa5f73098",
"identifier": "i613b844f9b503172424717ebbfa5f73098",
"updated_at": "2022-05-23 01:36:53"
}
]
}
]
Want to transform like below--
using below link to convert same to csv. selecting Pivot data down instead of flattening option.
https://www.convertcsv.com/json-to-csv.htm same i want to write transformation. Could you please help me.
I am not sure why you want to use PIVOT when flatten works really nicely
Ah that was the thing to do in the online tool...
select f1.value:uri as uri
,f1.value:updated_at as updated_at
,f2.value:type as "interactionData//0//type"
,f2.value:"nb choice" as "interactionData//0//nu choice"
,f2.value:responseIdentifier as "interactionData//0//responseIdentifier"
from data
,table(flatten(input=>data.json)) as f1
,table(flatten(input=>f1.value:interactionData)) as f2
gives:
URI
UPDATED_AT
interactionData//0//type
interactionData//0//nu choice
interactionData//0//responseIdentifier
"http://www.awer.com/onasdgfgies/addhh.rdf#i613b844f9b503172424717ebbfa5f73098"
"2022-07-27 09:16:43"
"Choice"
4
"RESPONSE_A"
"http://www.awer.com/onasdgfgies/addhh.rdf#i613b844f9b503172424717ebbfa5f73098"
"2022-07-27 09:16:43"
"Choice"
6
"RESPONSE_B"
albeit, I would cast those values to types like:
select f1.value:uri::text as uri
,f1.value:updated_at::timestamp_ntz as updated_at
,f2.value:type::text as "interactionData//0//type"
,f2.value:"nb choice"::number as "interactionData//0//nu choice"
,f2.value:responseIdentifier::text as "interactionData//0//responseIdentifier"
from data
,table(flatten(input=>data.json)) as f1
,table(flatten(input=>f1.value:interactionData)) as f2
Related
[
{
"id": 0.5256669517010202,
"color": false,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5901705709044824,
"color": false,
"selected": false,
"type": [
{
"id": 0.30332161644408817,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5423422175390649,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.959208393000617,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
}
],
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5933110602496239,
"color": false,
"selected": false,
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
}
]
I think you should use Map method
const data = [
{
"id": 0.5256669517010202,
"color": false,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5901705709044824,
"color": false,
"selected": false,
"type": [
{
"id": 0.30332161644408817,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5423422175390649,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.959208393000617,
"color": true,
"selected": false,
"name": "",
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
}
],
"label": "",
"fieldName": "",
"required": "",
"validation": ""
},
{
"id": 0.5933110602496239,
"color": false,
"selected": false,
"type": "",
"label": "",
"fieldName": "",
"required": "",
"validation": ""
}
]
data.map((item) => item.id)
Just Try!
You should declared attribute type as Array always!
data.map(Item => (
Item.type.map(Item => ())
))
the map method is suitable here. For example you have your all data within state or another variable, well you can map throw it:
<div>
{yourData?.length && yourData.map(item => {
return(
<span>{item.id}</span>
...
<div>{item.type.map(typeItem => {
return(
<span>{typeItem.id}</span>
...
)
})
)})}
</div>
I have been working on a COVID-19 dashboard where I want to display the daily cases and daily deaths in the line graph. I can get the data from the following api https://api.covid19api.com/total/dayone/country/United%20Kingdom but it return me the total commutative cases and total commutative deaths on the given date. The data returned is in the following structure
const data = [
{
"Country": "United Kingdom",
"CountryCode": "",
"Province": "",
"City": "",
"CityCode": "",
"Lat": "0",
"Lon": "0",
"Confirmed": 190584,
"Deaths": 28734,
"Recovered": 0,
"Active": 161850,
"Date": "2020-05-04T00:00:00Z"
},
{
"Country": "United Kingdom",
"CountryCode": "",
"Province": "",
"City": "",
"CityCode": "",
"Lat": "0",
"Lon": "0",
"Confirmed": 194990,
"Deaths": 29427,
"Recovered": 0,
"Active": 165563,
"Date": "2020-05-05T00:00:00Z"
},
{
"Country": "United Kingdom",
"CountryCode": "",
"Province": "",
"City": "",
"CityCode": "",
"Lat": "0",
"Lon": "0",
"Confirmed": 201101,
"Deaths": 30076,
"Recovered": 0,
"Active": 171025,
"Date": "2020-05-06T00:00:00Z"
}
]
Where Confirmed is the total number of cases detected on that day. To calculate the daily cases on the specific day we can subtract the confirmed from the previous confirmed of previous date. For example 2020-05-05 the number of cases confirmed on that day can be calculated by subtracting the number of cases on 20-05-04 the previous day. So the calculation would be 194990- 190584 = 4442. For the first object of the array the value stays the same since there is no previous record to subtract from as I will be fetching the day one when a case was detected in that country. Therefore the desired data would be the following
const desiredData= [
{
"Country": "United Kingdom",
"CountryCode": "",
"Province": "",
"City": "",
"CityCode": "",
"Lat": "0",
"Lon": "0",
"Confirmed": 190584,
"Deaths": 28734,
"Recovered": 0,
"Active": 161850,
"Date": "2020-05-04T00:00:00Z"
},
{
"Country": "United Kingdom",
"CountryCode": "",
"Province": "",
"City": "",
"CityCode": "",
"Lat": "0",
"Lon": "0",
"Confirmed": 4442,
"Deaths": 29427,
"Recovered": 0,
"Active": 165563,
"Date": "2020-05-05T00:00:00Z"
},
{
"Country": "United Kingdom",
"CountryCode": "",
"Province": "",
"City": "",
"CityCode": "",
"Lat": "0",
"Lon": "0",
"Confirmed": 6111,
"Deaths": 30076,
"Recovered": 0,
"Active": 171025,
"Date": "2020-05-06T00:00:00Z"
}
]
I am using Vue.js I think this could be a basic javascript function which can loop through the array and subtract the "Confirmed" of current object from the "Confirmed" of previous object. Please do let me know how this can be acheived. Many Thanks
You can use something like this:
result = data.map((record, index, allRecords) => {
const previous = allRecords[index - 1] || {
Confirmed: 0
}
return {
...record,
newConfirmed: record.Confirmed - previous.Confirmed
}
});
Which will give you a result such as this which includes the "newConfirmed" key and value:
[{
"Country": "United Kingdom",
"CountryCode": "",
"Province": "",
"City": "",
"CityCode": "",
"Lat": "0",
"Lon": "0",
"Confirmed": 190584,
"Deaths": 28734,
"Recovered": 0,
"Active": 161850,
"Date": "2020-05-04T00:00:00Z",
"newConfirmed": 190584
}, {
"Country": "United Kingdom",
"CountryCode": "",
"Province": "",
"City": "",
"CityCode": "",
"Lat": "0",
"Lon": "0",
"Confirmed": 194990,
"Deaths": 29427,
"Recovered": 0,
"Active": 165563,
"Date": "2020-05-05T00:00:00Z",
"newConfirmed": 4406
}, {
"Country": "United Kingdom",
"CountryCode": "",
"Province": "",
"City": "",
"CityCode": "",
"Lat": "0",
"Lon": "0",
"Confirmed": 201101,
"Deaths": 30076,
"Recovered": 0,
"Active": 171025,
"Date": "2020-05-06T00:00:00Z",
"newConfirmed": 6111
}]
This question already has answers here:
Swift Dynamic Variable Name depend on value
(2 answers)
Create a variable in swift with dynamic name
(4 answers)
Swift: Converting a string into a variable name
(1 answer)
Closed 3 years ago.
Is there a way to define name of variable from value(array)?
I need it for automatically creating arrays, but I don't want type name manually, rather have it chosen from an array.
dataEmail = ["1", "POS101582781", "2018.10.26 10:02", "Buy", "1", "VMID", "29.435", "", "", "", "30.42", "0.99", "30.42\n2", "POS104121282", "2018.12.10 10:00", "Buy", "1", "PSN", "1940", "", "", "", "2440", "5", "24.4\n3", "POS101582480", "2018.10.26 10:00", "Buy", "2", "HL", "1796.5", "", "", "", "1730", "-1.33", "34.6\n4", "POS101582499", "2018.10.26 10:00", "Buy", "8", "INVP", "473.6", "", "", "", "493.4", "1.58", "39.47\n5", "POS102186690", "2018.11.06 10:00", "Buy", "40", "VOD", "153.63", "", "", "", "134.38", "-7.7", "53.75\n6", "POS105530053", "2019.01.04 10:00", "Buy", "5", "MKS", "253.4", "", "", "", "272.5", "0.96", "13.63\n7", "POS102224924", "2018.11.06 17:52", "Buy", "14", "EVR", "488.15", "", "", "", "563.4", "10.54", "78.88\n8", "POS102087914", "2018.11.02 17:32", "Buy", "59", "DC", "164.112", "", "", "", "133.2", "-18.24", "78.59\n9", "POS101582520", "2018.10.26 10:00", "Buy", "20", "BT", "241.4", "", "", "", "214.9", "-5.3", "42.98\n10", "POS101582491", "2018.10.26 10:00", "Buy", "101", "LLOY", "55.5975", "", "", "", "63.58", "8.06", "64.22\n11", "POS101582545", "2018.10.26 10:00", "Buy", "26", "AV", "413.662", "", "", "", "423.2", "2.48", "110.03\n12", "POS104121258", "2018.12.10 10:00", "Buy", "10", "PTEC", "389.6", "", "", "", "420.9", "3.13", "42.09\n13", "POS104962193", "2018.12.24 10:40", "Buy", "11", "RMG", "286.009", "", "", "", "283.4", "-0.29", "31.17\n14", "POS105487268", "2019.01.03 18:29", "Buy", "22", "CREI", "115.0909", "", "", "", "113.6", "-0.33", "24.99\n15", "POS108707475", "2019.02.14 10:00", "Buy", "4", "IMB", "2640", "", "", "", "2508.5", "-5.26", "100.34\n16", "POS102853078", "2018.11.16 11:45", "Buy", "3", "HMSO", "418.067", "", "", "", "377.9", "-1.21", "11.34\n17", "POS103378446", "2018.11.27 10:12", "Buy", "60", "CNCT", "37.3667", "", "", "", "38.65", "0.77", "23.19"]
let arrayName = ["VMID", "PSN", "HL", "INVP", "VOD", "MKS", "EVR", "DC", "BT", "LLOY", "AV", "PTEC", "RMG", "CREI", "IMB", "HMSO", "CNCT"]
func createStockSet (){
var indexNumber = 1
for n in 0...16 {
var arrayName[0] = StockClass(transactionName: dataEmail[indexNumber], date: dataEmail[indexNumber+1], type: dataEmail[indexNumber+2], amount: dataEmail[indexNumber+3], stockTinker: dataEmail[indexNumber+4], boughtPrice: dataEmail [indexNumber+5], nowPrice: dataEmail[indexNumber+6], floatingResult: dataEmail[indexNumber+9], margin: dataEmail[indexNumber+10])
indexNumber + 3
}}
let for an instance
{
"E-mail Address": "fultonlevy#ewaves.com",
"Related name": "",
"Home Address 2": "",
"Anniversary": "",
"First Name": "Rios",
"Business Address 2": "",
"Department": "",
"Display Name": "Baker Adkins",
"Home State": "",
"Business Country": "",
"Home Street": "",
"Birthday": "",
"Home Country": "",
"Pager": "",
"Categories": "",
"Home City": "",
"E-mail 3 Address": "bentleymccoy#cosmetex.com",
"Home Fax": "",
"Gender": "",
"Notes": "proident",
"Country Code": "",
"Job Title": "",
"Business Address": "",
"Web Page 2": "",
"Mobile Phone": "",
"Organization": "",
"Home Phone": "(962) 514-3534",
"E-mail 2 Address": "sheenaramirez#grupoli.com",
"Last Name": "Fisher",
"Nickname": "",
"Business Fax": "",
"Home Postal Code": "",
"Business Phone": "",
"Business Postal Code": "",
"Web Page": "",
"Business City": "",
"Business State": ""
}
<input ng-model="disName" type="text">
this is a specific object in a array of objects.
How can I modify a specific value for a key for suppose [key = Display Name] and with change in input value how can I modify it in object?
In angularJS you'll bind the object property to the input using ng-model.
There's no need to listen any change, because the framework takes care of that.
¿Who provides this object to the <input>? The controller, exposing the object through this.
Here's a working example using components.
https://plnkr.co/edit/lfD1LgML0nuRURKX4DCw?p=preview
As you can see, you'll need to use bracket notation because of the use of spaces on your object keys...
<input ng-model="$ctrl.obj['Display Name']">
On a real world example, I suppose your data will be provided using a service, as you can see in this example:
https://plnkr.co/edit/fp1fBC59dJLettJBvD2p?p=preview
Hope it helps!
I want to have the JSON below as an array with duplicated key values, i.e.:
"2016-09-16":{"available":"1","bind":0,"info":"","notes":"","price":"","promo":"","status":"booked"}
twice. How can I do that?
{
"2016-06-28": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-06-29": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-06-30": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-07-04": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-07-05": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-07-06": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-07-07": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-16": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-15": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-14": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-13": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-16": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
},
"2016-09-17": {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}
}
JSON with duplicate keys in the same object is not reliable across JSON parsers (some will choke, some will give you only the value of the last occurrence) and not useful in any case. Use arrays of objects for the values of those date keys, not individual objects:
{
"2016-06-29": [{
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}],
"2016-09-16": [{
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}, {
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}],
"2016-09-15": [{
"available": "1",
"bind": 0,
"info": "",
"notes": "",
"price": "",
"promo": "",
"status": "booked"
}]
}
(Data shortened for clarity.)
In the above, note how 2016-06-29 and 2016-09-15 have arrays with just one entry, but 2016-09-16 has an array with two entries.