Form a JSON Object from array of array
Input Data with Singleline Array
{
"bizdata_dataset": {
"values": [["Order ID",
"Country",
"City",
"Customer Type",
"Item Category",
"Item",
"Quantity",
"Amount"],
["42420",
"United States",
"Henderson",
"Consumer",
"Furniture",
"Bookcases",
"2",
"261.96"],
["34637",
"United States",
"Henderson",
"Consumer",
"Furniture",
"Chairs",
"2",
"260"],
["37892",
"United States",
"Henderson",
"Consumer",
"Furniture",
"Bookcases",
"2",
"221.96"]]
}
}
Below is the pycode ops
When we want to run a script for the data which is flowing. In this case the data will be stored in pycode_data
variable, so use this variable for making changes in data using your script.
Responsedata=[]
new_data = pycode_data['values']
headers = new_data[0] # Get the headers from the first row
data_rows = new_data[1:] # Get the data rows
num_columns = len(headers)
result_rows = []
for row in data_rows:
result_row = {}
for i in range(num_columns):
result_row[headers[i]] = row[i]
result_rows.append(result_row)
res = {"values":result_rows}
pycode_data.update(res)
In the above example we can see that we are running a script to make changes in the existing data so we are using pycode_data
variable.
Output data after applying Python Pycode
{
"bizdata_dataset": {
"values": [{
"Order ID": "42420",
"Country": "United States",
"City": "Henderson",
"Customer Type": "Consumer",
"Item Category": "Furniture",
"Item": "Bookcases",
"Quantity": "2",
"Amount": "261.96"
}, {
"Order ID": "34637",
"Country": "United States",
"City": "Henderson",
"Customer Type": "Consumer",
"Item Category": "Furniture",
"Item": "Chairs",
"Quantity": "2",
"Amount": "260"
}, {
"Order ID": "37892",
"Country": "United States",
"City": "Henderson",
"Customer Type": "Consumer",
"Item Category": "Furniture",
"Item": "Bookcases",
"Quantity": "2",
"Amount": "221.96"
}
],
"items": []
}
}