Flatten a complex nested JSON using jolt transform - json

I am facing a problem, transforming a very complex nested JSON using jolt transformation. Input and output detail is given below.
Input JSON
{
"OutboundSchedulingLT": {
"DepertureSite": "0DE1",
"ShippingPoint": "010D",
"LeadTimes": {
"TransportationLT": [
{
"DestinationSite": "0DEA",
"DestinationLT": [
{
"ShippingCondition": "01",
"DestinationSiteLT": "3"
},
{
"ShippingCondition": "02",
"DestinationSiteLT": "4"
},
{
"ShippingCondition": "OA",
"DestinationSiteLT": "2"
}
]
},
{
"DestinationSite": "0DEB",
"DestinationLT": [
{
"ShippingCondition": "01",
"DestinationSiteLT": "1"
},
{
"ShippingCondition": "02",
"DestinationSiteLT": "2"
},
{
"ShippingCondition": "OA",
"DestinationSiteLT": "3"
}
]
}
],
"DNCreationLeadTimes": {
"DNCreationLeadTime": [
{
"DistributionChannel": "40",
"OrderType": "ZFUT",
"OrderReason": "",
"DNCreationLT": "3"
},
{
"DistributionChannel": "40",
"OrderType": "ZOR",
"OrderReason": "",
"DNCreationLT": "3"
},
{
"DistributionChannel": "70",
"OrderType": "ZU20",
"OrderReason": "RDC",
"DNCreationLT": "1"
}
]
},
"DNProcessingLeadTimes": {
"DNProcessingLeadTime": [
{
"DistributionChannel": "40",
"OrderType": "ZFUT",
"OrderReason": "",
"DNprocessingLT": "2"
},
{
"DistributionChannel": "40",
"OrderType": "ZOR",
"OrderReason": "",
"DNprocessingLT": "4"
},
{
"DistributionChannel": "70",
"OrderType": "ZU20",
"OrderReason": "RDC",
"DNprocessingLT": "3"
}
]
},
"DNLoadingLeadTimes": {
"DNLoadingLeadTime": [
{
"DistributionChannel": "40",
"ShippingCondition": "O1",
"OrderType": "ZFUT",
"OrderReason": "",
"DNLoadingLT": "3"
},
{
"DistributionChannel": "40",
"ShippingCondition": "O1",
"OrderType": "ZOR",
"OrderReason": "",
"DNLoadingLT": "3"
},
{
"DistributionChannel": "70",
"ShippingCondition": "O1",
"OrderType": "ZU20",
"OrderReason": "RDC",
"DNLoadingLT": "1"
}
]
},
"VASLeadTimes": {
"VASLeadTime": [
{
"VASCode": "L01",
"VASLT": "2"
},
{
"VASCode": "P02",
"VASLT": "3"
}
]
}
}
}
}
I want the below columns in flattened way
DepertureSite,DestinationSite,DestinationSiteLT,DistributionChannel,OrderType,OrderReason,DNCreationLT,DNprocessingLT,DNLoadingLT,VASCode,VASLT
Jolt Spec I tried
[
{
"operation": "shift",
"spec": {
"OutboundSchedulingLT": {
"DepertureSite": "DepertureSite",
"LeadTimes": {
"TransportationLT": {
"*": {
"DestinationSite": "DestinationSite",
"DestinationLT": {
"*": {
"DestinationSiteLT": "DestinationSiteLT"
}
}
}
},
"DNCreationLeadTimes": {
"DNCreationLeadTime": {
"*": {
"DistributionChannel": "DistributionChannel",
"OrderType": "OrderType",
"OrderReason": "OrderReason",
"DNCreationLT": "DNCreationLT"
}
}
},
"DNProcessingLeadTimes": {
"DNProcessingLeadTime": {
"*": {
"DNprocessingLT": "DNprocessingLT"
}
}
},
"DNLoadingLeadTimes": {
"DNLoadingLeadTime": {
"*": {
"DNLoadingLT": "DNLoadingLT"
}
}
},
"VASLeadTimes": {
"VASLeadTime": {
"*": {
"VASCode": "VASCode",
"VASLT": "VASLT"
}
}
}
}
}
}
}
]
But its not coming as expected.
Pls help
Output Expected
[
{
"DepertureSite": "0DE1",
"DestinationSite": "0DEA",
"DestinationSiteLT": "3",
"DistributionChannel": "40",
"OrderType": "ZOR",
"OrderReason": "",
"DNCreationLT": "3",
"DNprocessingLT": "2",
"DNLoadingLT": "3",
"VASCode": "L01",
"VASLT": "2"
},
{
"DepertureSite": "0DE1",
"DestinationSite": "0DEA",
"DestinationSiteLT": "4",
"DistributionChannel": "70",
"OrderType": "ZU20",
"OrderReason": "RDC",
"DNprocessingLT": "4",
"DNLoadingLT": "3",
"VASCode": "L01",
"VASLT": "2"
},
{
"DepertureSite": "0DE1",
"DestinationSite": "0DEA",
"DestinationSiteLT": "2",
"DistributionChannel": "70",
"OrderType": "ZU20",
"OrderReason": "RDC",
"DNCreationLT": "1",
"DNprocessingLT": "3",
"DNLoadingLT": "1",
"VASCode": "L01",
"VASLT": "2"
},
{
"DepertureSite": "0DE1",
"DestinationSite": "0DEB",
"DestinationSiteLT": "1",
"DistributionChannel": "40",
"OrderType": "ZOR",
"OrderReason": "",
"DNCreationLT": "3",
"DNprocessingLT": "2",
"DNLoadingLT": "3",
"VASCode": "P02",
"VASLT": "3"
},
{
"DepertureSite": "0DE1",
"DestinationSite": "0DEB",
"DestinationSiteLT": "2",
"DistributionChannel": "70",
"OrderType": "ZU20",
"OrderReason": "RDC",
"DNprocessingLT": "4",
"DNLoadingLT": "3",
"VASCode": "P02",
"VASLT": "3"
},
{
"DepertureSite": "0DE1",
"DestinationSite": "0DEB",
"DestinationSiteLT": "3",
"DistributionChannel": "70",
"OrderType": "ZU20",
"OrderReason": "RDC",
"DNCreationLT": "1",
"DNprocessingLT": "3",
"DNLoadingLT": "1",
"VASCode": "P02",
"VASLT": "3"
}
]

You can use the following shift transformation as walking through the DestinationLT object spec
[
{
"operation": "shift",
"spec": {
"OutboundSchedulingLT": {
"LeadTimes": {
"TransportationLT": {
"*": {
"DestinationLT": {
"*": {
"#5,DepertureSite": "&3[#2].DepertureSite",
"#2,DestinationSite": "&3[#2].DestinationSite",
"DestinationSiteLT": "&3[#2].&",
"#4,DNCreationLeadTimes.DNCreationLeadTime[&].DistributionChannel": "&3[#2].DistributionChannel",
"#4,DNCreationLeadTimes.DNCreationLeadTime[&].OrderType": "&3[#2].OrderType",
"#4,DNCreationLeadTimes.DNCreationLeadTime[&].OrderReason": "&3[#2].OrderReason",
"#4,DNCreationLeadTimes.DNCreationLeadTime[&].DNCreationLT": "&3[#2].DNCreationLT",
"#4,DNProcessingLeadTimes.DNCreationLeadTime[&].DNProcessingLeadTime": "&3[#2].DNprocessingLT",
"#4,DNLoadingLeadTimes.DNLoadingLeadTime[&].DNLoadingLT": "&3[#2].DNLoadingLT",
"#4,VASLeadTimes.VASLeadTime[&].VASCode": "&3[#2].VASCode",
"#4,VASLeadTimes.VASLeadTime[&].VASLT": "&3[#2].VASLT"
}
}
}
}
}
}
}
},
{// get rid of the object keys generated within the previous spec
"operation": "shift",
"spec": {
"*": {
"*": ""
}
}
}
]

Related

JOLT transformation for carrying parent fields to child

I trying to apply JOLT transformation to convert one JSON structure into another. The JOLT spec I came up with does not distribute parent fields to child as I want and is explained in the example below. Could you please help with the mistake I'm doing in the spec?
My input JSON
{
"numberOfBlocks": 2,
"signatoryBlocks": [
{
"block": [
{
"role": "abcd"
},
{
"order": "1"
},
{
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp"
},
{
"signatories": [
{
"email": "joe.smith#abcd.com",
"name": "Joe Smith",
"initials": "JS",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_joe",
"sms": "1234"
},
{
"email": "jane.doe#abcd.com",
"name": "Jane Doe",
"initials": "JD",
"capacity": "Director",
"company": "abcd AG",
"oneTimePassword": "test_jane",
"sms": "4567"
}
]
}
]
},
{
"block": [
{
"role": "Signer 2"
},
{
"order": "1"
},
{
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp"
},
{
"signatories": [
{
"email": "rachel.smith#abcd.com",
"name": "Rachel Smith",
"initials": "RS",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_rachel",
"sms": ""
},
{
"email": "joe.bloggs#abcd.com",
"name": "Joe Bloggs",
"initials": "JB",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_joe",
"sms": "111"
}
]
}
]
}
]
}
My JOLT spec
[
{
"operation": "shift",
"spec": {
"#3186": "entityId",
"#160": "entityTypeId",
"#1007": "clientId",
"*": ["rawData.&0", "formatedData.&0"]
}
},
{
"operation": "shift",
"spec": {
"*": "&0",
"formatedData": {
"signatoryBlocks": {
"*": {
"block": {
"3": {
"signatories": {
"*": {
"#3": {
"0": {
"role": "formatedData.[#8].roleGroupName"
},
"1": {
"order": "formatedData.[#8].order"
},
"2": {
"signatureProviderName": "formatedData.[#8].signatureProviderName"
}
},
"*": "formatedData.[#6].userDetails[#2].&0"
}
}
}
}
}
}
}
}
},
{
"operation": "cardinality",
"spec": {
"formatedData": {
"*": {
"roleGroupName": "ONE",
"order": "ONE",
"signatureProviderName": "ONE"
}
}
}
}
]
Output I am getting using my JOLT spec
{
"entityId": "3186",
"entityTypeId": "160",
"clientId": "1007",
"rawData": {
"numberOfBlocks": 2,
"signatoryBlocks": [
{
"block": [
{
"role": "abcd"
},
{
"order": "1"
},
{
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp"
},
{
"signatories": [
{
"email": "joe.smith#abcd.com",
"name": "Joe Smith",
"initials": "JS",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_joe",
"sms": "1234"
},
{
"email": "jane.doe#abcd.com",
"name": "Jane Doe",
"initials": "JD",
"capacity": "Director",
"company": "abcd AG",
"oneTimePassword": "test_jane",
"sms": "4567"
}
]
}
]
},
{
"block": [
{
"role": "Signer 2"
},
{
"order": "1"
},
{
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp"
},
{
"signatories": [
{
"email": "rachel.smith#abcd.com",
"name": "Rachel Smith",
"initials": "RS",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_rachel",
"sms": ""
},
{
"email": "joe.bloggs#abcd.com",
"name": "Joe Bloggs",
"initials": "JB",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_joe",
"sms": "111"
}
]
}
]
}
]
},
"formatedData": [
{
"roleGroupName": "abcd",
"order": "1",
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp",
"userDetails": [
{
"email": "joe.smith#abcd.com",
"name": "Joe Smith",
"initials": "JS",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_joe",
"sms": "1234"
},
{
"email": "jane.doe#abcd.com",
"name": "Jane Doe",
"initials": "JD",
"capacity": "Director",
"company": "abcd AG",
"oneTimePassword": "test_jane",
"sms": "4567"
}
]
},
{
"roleGroupName": "Signer 2",
"order": "1",
"signatureProviderName": "universalsignaturepen_opentrust_hash_tsp",
"userDetails": [
{
"email": "rachel.smith#abcd.com",
"name": "Rachel Smith",
"initials": "RS",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_rachel",
"sms": ""
},
{
"email": "joe.bloggs#abcd.com",
"name": "Joe Bloggs",
"initials": "JB",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_joe",
"sms": "111"
}
]
}
]
}
Output I want
{
"entityId": 3186,
"entityTypeId": 160,
"clientId": 1007,
"rawData": "complete_body_of_input_JSON_here",
"formatedData": [
{
"roleGroupName": "abcd",
"order": "1",
"signatureProvider": "universalsignaturepen_opentrust_hash_tsp",
"userDetails": [
{
"email": "joe.smith#abcd.com",
"name": "Joe Smith",
"initials": "JS",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_joe",
"sms": "1234"
}
]
},
{
"roleGroupName": "abcd",
"order": "1",
"signatureProvider": "universalsignaturepen_opentrust_hash_tsp",
"userDetails": [
{
"email": "jane.doe#abcd.com",
"name": "Jane Doe",
"initials": "JD",
"capacity": "Director",
"company": "abcd AG",
"oneTimePassword": "test_jane",
"sms": "4567"
}
]
},
{
"roleGroupName": "Signer 2",
"order": "1",
"signatureProvider": "universalsignaturepen_opentrust_hash_tsp",
"userDetails": [
{
"email": "rachel.smith#abcd.com",
"name": "Rachel Smith",
"initials": "RS",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_rachel",
"sms": ""
}
]
},
{
"roleGroupName": "Signer 2",
"order": "1",
"signatureProvider": "universalsignaturepen_opentrust_hash_tsp",
"userDetails": [
{
"email": "joe.bloggs#abcd.com",
"name": "Joe Bloggs",
"initials": "JB",
"capacity": "Authorised Signatory",
"company": "abcd AG",
"oneTimePassword": "test_joe",
"sms": "111"
}
]
}
]
}
What am I doing wrong?
Here is the answer
[
{
"operation": "shift",
"spec": {
"#3186": "entityId",
"#160": "entityTypeId",
"#1007": "clientId",
"*": ["rawData.&0","formatedData.&0"]
}
},
{
"operation": "shift",
"spec": {
"*": "&0",
"formatedData": {
"signatoryBlocks": {
"*": {
"block": {
"3": {
"signatories": {
"*": {
"#3": {
"0": {
"role": "formatedData.[#8].[#6].[#4].roleGroupName"
},
"1": {
"order": "formatedData.[#8].[#6].[#4].order"
},
"2": {
"signatureProviderName": "formatedData.[#8].[#6].[#4].signatureProviderName"
}
},
"*": "formatedData.[#6].[#4].[#2].userDetails.&0"
}
}
}
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"entityId": "=toInteger",
"entityTypeId": "=toInteger",
"clientId": "=toInteger"
}
},
{
"operation": "shift",
"spec": {
"*": "&0",
"formatedData": {
"*": {
"*": {
"*": "formatedData"
}
}
}
}
}
]

How to Add an Object to a Json Array Depending a value of another Key in the File Using JoltTransformationJson in NiFi

This is my first time to use JoltTransformationJson, so I have limited knowledge and experience on that. Please help me with this complicated project.
Request:
when the payment.code <> "paid", I have to do the following two things for the file.
to change the payment.code ="denied" and payment.text ="denied"
to add a JSON object to item.ADJ
When the payment.code =="paid", don't need to change anything.
Input :
{
"resourceType": "E",
"id": "11",
"identifier": [
{
"type": {
"coding": [
{
"system": "sys1",
"code": "aaa"
}
]
},
"value": "212"
},
{
"type": {
"coding": [
{
"system": "sys2",
"code": "RRR"
}
]
},
"value": "367"
}
],
"status": "active",
"created": "2021-08-05T02:43:48+00:00",
"outcome": "complete",
"item": [
{
"sequence": 1,
"product": {
"coding": [
{
"system": "example",
"code": "abc",
"display": "ABC"
}
],
"text": "ABC"
},
"servicedDate": "2021-08-04",
"quantity": {
"value": 60
},
"ADJ": [
{
"category": {
"coding": [
{
"system": "code1",
"code": "code1",
"display": "CODE1"
}
],
"text": "CODE1"
},
"amount": {
"value": 46.45,
"currency": "USD"
}
},
{
"category": {
"coding": [
{
"system": "code2",
"code": "code2",
"display": "CODE2"
}
],
"text": "CODE2"
},
"amount": {
"value": 12.04,
"currency": "USD"
}
}
]
}
],
"payment": {
"type": {
"coding": [
{
"system": "http://payment.com",
"code": "reversed/cancelled"
}
],
"text": "cancelled"
}
}
}
My Expected Output :
{
"resourceType": "E",
"id": "11",
"identifier": [
{
"type": {
"coding": [
{
"system": "sys1",
"code": "aaa"
}
]
},
"value": "212"
},
{
"type": {
"coding": [
{
"system": "sys2",
"code": "RRR"
}
]
},
"value": "367"
}
],
"status": "active",
"created": "2021-08-05T02:43:48+00:00",
"outcome": "complete",
"item": [
{
"sequence": 1,
"product": {
"coding": [
{
"system": "example",
"code": "abc",
"display": "ABC"
}
],
"text": "ABC"
},
"servicedDate": "2021-08-04",
"quantity": {
"value": 60
},
"ADJ": [
{
"category": {
"coding": [
{
"system": "code1",
"code": "code1",
"display": "CODE1"
}
],
"text": "CODE1"
},
"amount": {
"value": 46.45,
"currency": "USD"
}
},
{
"category": {
"coding": [
{
"system": "code2",
"code": "code2",
"display": "CODE2"
}
],
"text": "CODE2"
},
"amount": {
"value": 12.04,
"currency": "USD"
}
},
{// new object I want to insert into
"category": {
"coding": [
{
"system": "sys_denail",
"code": "denialreason"
}
],
"reason": {
"coding": [
{
"system": "https://example.com",
"code": "A1"
}
],
"text": "unknown"
}}
}
]
}
],
"payment": {
"type": {
"coding": [
{
"system": "http://payment.com",
"code": "denied" //change the value to denied
}
],
"text": "denied" //change the value to denied
}
}
}
Edit : I've tried to answer the second case by myself to be evaluated after the first case is answered
Welcome to SO, please ask minimal and reproducible questions, and show your effort tried for the future.
What you need is to use a conditional logic along with placeholder values with ampersand symbols depending on the levels of each key name within the tree.
I have partially answered, which will handle the bottom part of your question. Indeed the logic for the rest(inserting an object to the array will be similiar)
So, consider having a look at the following solution
[
{
"operation": "shift",
"spec": {
"*": "&",
"payment": {
"type": {
"coding": {
"*": {
"*": "&4.&3.&2[&1].&",
"code": {
"paid": {
"#1": "&6.&5.&4[&3].&2",
"#(4,text)": "&6.text"
},
"*": {
"#denied": "&6.&5.&4[&3].code",
"#(4,text)": {
"#denied": "&6.text"
}
}
}
}
}
}
}
}
}
]
Edit(for your own answer related to adding an object):
your current idea of using shift after default transformation spec is pretty good, you can rephrase like
[
{
"operation": "default",
"spec": {
"temp_deny": {
"denialreason": {
"category": {
"coding": [
{
"system": "sys_denail",
"code": "denialreason"
}
],
"reason": {
"coding": [
{
"system": "https://example.com",
"code": "A1"
}
],
"text": "unknown"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"item": {
"*": {
"*": "&2[&1].&",
"ADJ": {
"#": "&3[&2].&",
"#(4,temp_deny)": "&3[&2].&"
}
}
}
}
}
]

JOLT get only one value from an array inside an array

I've been trying to figure out how to get the first value out of an array in my events array in this JSON.
I think I must do something with Cardinality but I can't quite figure it out so any help would be appreciated.
This is what my JSON looks like
{
"rootid": "19718",
"clloadm": "2021-06-01T22:40:02",
"clload": "2021-06-01T21:21:39",
"date": "2021-05-25T21:52:30",
"events": [
{
"done": {
"id": "e0",
"value": "2021-05-29T08:08:19"
},
"id": "e0_event",
"started": {
"id": "e0",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e1",
"value": "2021-05-27T02:20:25"
},
"id": "e1_event",
"started": {
"id": "e1",
"value": "2021-05-27T02:20:25"
},
"status": "complete"
},
{
"done": {
"id": "e2",
"value": "2021-05-29T08:08:19"
},
"id": "e2_event",
"started": {
"id": "e2",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e3",
"value": "2021-05-29T08:08:19"
},
"id": "e3_event",
"started": {
"id": "e3",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e4",
"value": "2021-05-29T08:08:19"
},
"id": "e4_event",
"started": {
"id": "e4",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
}
],
"ids": [
{
"id": "id",
"source": "source",
"value": "value"
}
]
}
My Jolt Spec
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"#id": {
"e0": { "#(2,value)": "&" },
"e4": { "#(2,value)": "&" }
}
}
}
},
"ids": {
"*": {
"#value": "#id"
}
}
}
}
]
The result I get:
{
"rootid" : "19718",
"clloadm" : "2021-06-01T22:40:02",
"clload" : "2021-06-01T21:21:39",
"date" : "2021-05-25T21:52:30",
"e0" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"e4" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"id" : "value",
"new_id" : "value"
}
I would like the result to be more like this where only the first value is selected:
{
"rootid" : "19718",
"clloadm" : "2021-06-01T22:40:02",
"clload" : "2021-06-01T21:21:39",
"date" : "2021-05-25T21:52:30",
"e0" : "2021-05-29T08:08:19",
"e4" : "2021-05-29T08:08:19",
"id" : "value",
"new_id" : "value"
}
Edit:
I've tried adding the cardinality into my spec, but I can't seem to get the result I want.
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"#id": {
"e0": { "#(2,value)": "&" },
"e4": {
"operation": "cardinality",
"spec": {
"e4": "ONE"
}
}
}
}
}
},
"ids": {
"*": {
"#value": "#id"
}
}
}
}
]
Yes, you just can add a cardinality transformation such as
{
"operation": "cardinality",
"spec": {
"*": "ONE"
}
}
or optionally use e* wildcard just to restrict the result for the arrays with keys starting with the letter e such as
{
"operation": "cardinality",
"spec": {
"e*": "ONE"
}
}
Edit : just need to add to the current spec. So, you can use the following :
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"#id": {
"e0": {
"#(2,value)": "&"
},
"e4": {
"#(2,value)": "&"
}
}
}
}
},
"ids": {
"*": {
"#value": "#id"
}
}
}
},
{
"operation": "cardinality",
"spec": {
"e*": "ONE"
}
}
]

Selectively get certain arrays from inside an array in JSON using JOLT

I've been trying to get some fields out of a very long and complicated json format but not getting the output I want.
MY current spec obtains all events from the event array and lists them in the output. I'm unsure how to select specific events and only output those. Am not quite sure of the syntax
My JSON:
{
"rootid": "19718",
"clloadm": "2021-06-01T22:40:02",
"clload": "2021-06-01T21:21:39",
"date": "2021-05-25T21:52:30",
"events": [
{
"done": {
"id": "e0",
"value": "2021-05-29T08:08:19"
},
"id": "e0_event",
"started": {
"id": "e0",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e1",
"value": "2021-05-27T02:20:25"
},
"id": "e1_event",
"started": {
"id": "e1",
"value": "2021-05-27T02:20:25"
},
"status": "complete"
},
{
"done": {
"id": "e2",
"value": "2021-05-29T08:08:19"
},
"id": "e2_event",
"started": {
"id": "e2",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e3",
"value": "2021-05-29T08:08:19"
},
"id": "e3_event",
"started": {
"id": "e3",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e4",
"value": "2021-05-29T08:08:19"
},
"id": "e4_event",
"started": {
"id": "e4",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
}
],
"ids": [
{
"id": "id",
"source": "source",
"value": "value"
},
{
"id": "new_id",
"source": "new_source",
"value": "value"
}
]
}
My Jolt Spec that gets all events for now:
[
{
"operation": "shift",
"spec": {
"rootid": "rootid",
"clloadm": "clloadm",
"clload": "clload",
"date": "date",
"events": {
"*": {
"*": {
"#value": "#id"
}
}
},
"ids": {
"*": {
"#value": "#id"
}
}
}
}
]
The output I get:
{
"rootid" : "19718",
"clloadm" : "2021-06-01T22:40:02",
"clload" : "2021-06-01T21:21:39",
"date" : "2021-05-25T21:52:30",
"e0" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"e1" : [ "2021-05-27T02:20:25", "2021-05-27T02:20:25" ],
"e2" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"e3" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"e4" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"id" : "value",
"new_id" : "value"
}
The output I would like
{
"rootid" : "19718",
"clloadm" : "2021-06-01T22:40:02",
"clload" : "2021-06-01T21:21:39",
"date" : "2021-05-25T21:52:30",
"e0" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"e4" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"id" : "value",
"new_id" : "value"
}
You can write the individual keys e0 and e4 as conditional cases for #id key while rewriting the rest of the key-value pairs through "*":"&" representation such as
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"#id": {
"e0": { "#(2,value)": "&" },
"e4": { "#(2,value)": "&" }
}
}
}
},
"ids": {
"*": {
"#value": "#id"
}
}
}
}
]

JSON (from HTML Table) to CSV

I am working with a reports API from an Application which converts an HTML table into JSON using a method very similar to that shown in posts in Stack Overflow (example: HTML Table to JSON).
The JSON has an array of columns (for the NAMES of VALUES), then there is an array of rows which contain cells (for the VALUES).
I want to map this report to a canonical data model but it is horrible to work with. What I want to do is run some sort of script on the JSON which reverse what the original script put in place and turns it into an array that contains individual records, much like the rows of a CSV file.
Here's an example of a report I am referring to - horrible isn't it :)
My Question
Is there a way of turning this format of JSON (where it has an array for column names, an array for sections and inside an array of rows which relate to the column names), into a table of some sort?
{
"Header": {
"Time": "2016-03-30T16:10:19-07:00",
"ReportName": "GeneralLedger",
"ReportBasis": "Accrual",
"StartPeriod": "2016-01-01",
"EndPeriod": "2016-03-31",
"Currency": "GBP",
"Option": [
{
"Name": "NoReportData",
"Value": "false"
}
]
},
"Columns": {
"Column": [
{
"ColTitle": "Date",
"ColType": "tx_date"
},
{
"ColTitle": "Transaction Type",
"ColType": "txn_type"
},
{
"ColTitle": "No.",
"ColType": "doc_num"
},
{
"ColTitle": "Name",
"ColType": "name"
},
{
"ColTitle": "Memo/Description",
"ColType": "memo"
},
{
"ColTitle": "Split",
"ColType": "split_acc"
},
{
"ColTitle": "Amount",
"ColType": "subt_nat_amount"
},
{
"ColTitle": "Balance",
"ColType": "rbal_nat_amount"
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Current",
"id": "144"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Bill Payment (Cheque)",
"id": "181"
},
{
"value": "1"
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": "104478"
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-600.0"
},
{
"value": "-600.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill Payment (Cheque)",
"id": "184"
},
{
"value": "2"
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": "104478"
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-120.0"
},
{
"value": "-720.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Deposit",
"id": "180"
},
{
"value": ""
},
{
"value": "",
"id": ""
},
{
"value": "Opening Balance"
},
{
"value": "Opening Balance Equity",
"id": "137"
},
{
"value": "2400.0"
},
{
"value": "1680.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-23"
},
{
"value": "Payment",
"id": "186"
},
{
"value": "345678"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": ""
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "216.0"
},
{
"value": "1896.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Current"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "1896.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Debtors",
"id": "140"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": ""
},
{
"value": "-Split-",
"id": ""
},
{
"value": "216.0"
},
{
"value": "216.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": ""
},
{
"value": "-Split-",
"id": ""
},
{
"value": "108.0"
},
{
"value": "324.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-23"
},
{
"value": "Payment",
"id": "186"
},
{
"value": "345678"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": ""
},
{
"value": "Current",
"id": "144"
},
{
"value": "-216.0"
},
{
"value": "108.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Debtors"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "108.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Stock Asset",
"id": "136"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-01"
},
{
"value": "Stock Starting Value",
"id": "173"
},
{
"value": "START"
},
{
"value": "",
"id": ""
},
{
"value": "Round Neck T Shirt - Opening stock and value"
},
{
"value": "Opening Balance Equity",
"id": "137"
},
{
"value": "0.0"
},
{
"value": "0.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "-12.0"
},
{
"value": "-12.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "-24.0"
},
{
"value": "-36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "177"
},
{
"value": "2"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "0.0"
},
{
"value": "-36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "182"
},
{
"value": "3"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "-36.0"
},
{
"value": "-72.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "182"
},
{
"value": "3"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "-564.0"
},
{
"value": "-636.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "177"
},
{
"value": "2"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "600.0"
},
{
"value": "-36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "182"
},
{
"value": "3"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "0.0"
},
{
"value": "-36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "178"
},
{
"value": ""
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "600.0"
},
{
"value": "564.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Stock Asset"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "564.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Creditors",
"id": "138"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Bill Payment (Cheque)",
"id": "181"
},
{
"value": "1"
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": ""
},
{
"value": "Current",
"id": "144"
},
{
"value": "-600.0"
},
{
"value": "-600.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill Payment (Cheque)",
"id": "184"
},
{
"value": "2"
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": ""
},
{
"value": "Current",
"id": "144"
},
{
"value": "-120.0"
},
{
"value": "-720.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "185"
},
{
"value": ""
},
{
"value": "British Power",
"id": "72"
},
{
"value": ""
},
{
"value": "Utilities",
"id": "129"
},
{
"value": "192.15"
},
{
"value": "-527.85"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "183"
},
{
"value": ""
},
{
"value": "Printing Ink Supplies",
"id": "71"
},
{
"value": ""
},
{
"value": "-Split-",
"id": ""
},
{
"value": "1920.0"
},
{
"value": "1392.15"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "178"
},
{
"value": ""
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": ""
},
{
"value": "Stock Asset",
"id": "136"
},
{
"value": "720.0"
},
{
"value": "2112.15"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Creditors"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "2112.15"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "VAT Control",
"id": "142"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": ""
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "36.0"
},
{
"value": "36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": ""
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "18.0"
},
{
"value": "54.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "185"
},
{
"value": ""
},
{
"value": "British Power",
"id": "72"
},
{
"value": ""
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-9.15"
},
{
"value": "44.85"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "183"
},
{
"value": ""
},
{
"value": "Printing Ink Supplies",
"id": "71"
},
{
"value": ""
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-320.0"
},
{
"value": "-275.15"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "178"
},
{
"value": ""
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": ""
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-120.0"
},
{
"value": "-395.15"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for VAT Control"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "-395.15"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Opening Balance Equity",
"id": "137"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-01"
},
{
"value": "Stock Starting Value",
"id": "173"
},
{
"value": "START"
},
{
"value": "",
"id": ""
},
{
"value": "Round Neck T Shirt - Opening stock and value"
},
{
"value": "Stock Asset",
"id": "136"
},
{
"value": "0.0"
},
{
"value": "0.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Deposit",
"id": "180"
},
{
"value": ""
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Current",
"id": "144"
},
{
"value": "2400.0"
},
{
"value": "2400.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Opening Balance Equity"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "2400.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Sales of Product Income",
"id": "133"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "60.0"
},
{
"value": "60.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "120.0"
},
{
"value": "180.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Sales of Product Income"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "180.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Services",
"id": "131"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": "Print on Pocket"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "60.0"
},
{
"value": "60.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": "Print on Pocket"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "30.0"
},
{
"value": "90.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Services"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "90.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Cost of sales",
"id": "134"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "24.0"
},
{
"value": "24.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "12.0"
},
{
"value": "36.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Cost of sales"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "36.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
}
etc. I had to cut this JSON short, limited to 30000 characters.
What have you tried so far? This seems pretty straightforward. To get the rows into an array format you would do something like the following:
var data = {
"Header": {
"Time": "2016-03-30T16:10:19-07:00",
"ReportName": "GeneralLedger",
"ReportBasis": "Accrual",
"StartPeriod": "2016-01-01",
"EndPeriod": "2016-03-31",
"Currency": "GBP",
"Option": [{
"Name": "NoReportData",
"Value": "false"
}]
},
"Columns": {
"Column": [{
"ColTitle": "Date",
"ColType": "tx_date"
}, {
"ColTitle": "Transaction Type",
"ColType": "txn_type"
}, {
"ColTitle": "No.",
"ColType": "doc_num"
}, {
"ColTitle": "Name",
"ColType": "name"
}, {
"ColTitle": "Memo/Description",
"ColType": "memo"
}, {
"ColTitle": "Split",
"ColType": "split_acc"
}, {
"ColTitle": "Amount",
"ColType": "subt_nat_amount"
}, {
"ColTitle": "Balance",
"ColType": "rbal_nat_amount"
}]
},
"Rows": {
"Row": [{
"Header": {
"ColData": [{
"value": "Current",
"id": "144"
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}]
},
"Rows": {
"Row": [{
"ColData": [{
"value": "2016-03-16"
}, {
"value": "Bill Payment (Cheque)",
"id": "181"
}, {
"value": "1"
}, {
"value": "Teddy's T Shirt Supplier",
"id": "70"
}, {
"value": "104478"
}, {
"value": "Creditors",
"id": "138"
}, {
"value": "-600.0"
}, {
"value": "-600.0"
}],
"type": "Data"
}, {
"ColData": [{
"value": "2016-03-17"
}, {
"value": "Bill Payment (Cheque)",
"id": "184"
}, {
"value": "2"
}, {
"value": "Teddy's T Shirt Supplier",
"id": "70"
}, {
"value": "104478"
}, {
"value": "Creditors",
"id": "138"
}, {
"value": "-120.0"
}, {
"value": "-720.0"
}],
"type": "Data"
}, {
"ColData": [{
"value": "2016-03-17"
}, {
"value": "Deposit",
"id": "180"
}, {
"value": ""
}, {
"value": "",
"id": ""
}, {
"value": "Opening Balance"
}, {
"value": "Opening Balance Equity",
"id": "137"
}, {
"value": "2400.0"
}, {
"value": "1680.0"
}],
"type": "Data"
}, {
"ColData": [{
"value": "2016-03-23"
}, {
"value": "Payment",
"id": "186"
}, {
"value": "345678"
}, {
"value": "Maxamillion Enterprises",
"id": "68"
}, {
"value": ""
}, {
"value": "Debtors",
"id": "140"
}, {
"value": "216.0"
}, {
"value": "1896.0"
}],
"type": "Data"
}]
}
}]
}
};
function parse(data) {
var rows = [],
row, curRow, rowSegment;
for (var i = 0; i < data.Rows.Row.length; ++i) {
rowSegment = data.Rows.Row[i].Rows.Row;
for (var j = 0; j < rowSegment.length; ++j) {
row = [];
curRow = rowSegment[j].ColData;
for (var x = 0; x < curRow.length; ++x) {
row.push(curRow[x].value);
}
rows.push(row);
}
}
return rows;
}
var parsed = parse(data);
var rowEl, outEl = document.getElementById('html-out'),
val;
for (var i = 0; i < parsed.length; ++i) {
rowEl = document.createElement("div");
rowEl.setAttribute("class", "row");
rowEl.appendChild(document.createTextNode(parsed[i].join(', ')));
outEl.appendChild(rowEl);
}
<div id="html-out"></div>
Also, you would probably want to add the columns as the first row but this looks like it would get you the CSV-type data you are going for.