Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursively parsing JSON
    text
    copied!<p>I have a large JSON object that I created with Python, and I'm needing to display the information on a webpage now. My problem is the size of it; there are nested arrays and objects within, and it is several layers deep at points. I wrote an extremely inelegant (and buggy) JavaScript function to pull the data out, but this seems like a recursive problem to me, and I unfortunately am not used to thinking like that (yet). </p> <p>Does anyone know of a good solution to <strike>parsing</strike> reading such an object? My goal here is to really read this somewhat dynamically, since I'm going to have to do this many more times (and each time the object will be different, but with more or less the same structure). <b>The goal is to take this information and show it meaningfully on a web page.</b></p> <p>Let me know if I can elaborate further. </p> <p>Edit: Here's the object. I was away from my computer when I posted this, plus it's rather large. Parts of it that might be sensitive I've pulled out. And I'm using the JSON2 to parse this into something other than a string. It's just the sized and nestiness that's giving me a problem.</p> <p><code><pre> { "Loop300": [ { "Loop310": [ { "N1": { "idCode": "0400", "idQual": "ZZ", "name": "REDACTED", "entIdCode": "SF" }, "N3": [ { "address1": "REDACTED", "address2": "REDACTED" } ], "G61": [ { "contactFunctionCode": "CN", "commNumber": "REDACTED", "commNumQualifier": "TE", "name": "shipping" } ], "N4": [ {} ] } ], "L11": [], "S5": { "stopReasonCode": "LD", "stopSeqNum": "1" }, "Loop350": [ { "LAD": [], "OID": { "weight": "161", "poNum": "ASDF", "weightCode": "L", "unitMeasure": "CA", "refID": "THING", "quantity": "6" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "1", "desc": "STUFF" } } ] }, { "LAD": [], "OID": { "weight": "104", "poNum": "ZXMO", "weightCode": "L", "unitMeasure": "CA", "refID": "STUFF", "quantity": "6" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "2", "desc": "STUFF" } } ] }, { "LAD": [], "OID": { "weight": "1833", "poNum": "ASDF", "weightCode": "L", "unitMeasure": "CA", "refID": "THEBLOB", "quantity": "40" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "3", "desc": "STUFF" } } ] }, { "LAD": [], "OID": { "weight": "229", "poNum": "FDSA", "weightCode": "L", "unitMeasure": "CA", "refID": "BATMAN", "quantity": "6" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "4", "desc": "STUFF" } } ] } ], "AT5": [], "G62": [ { "date": "20100817", "datequalifier": "10" }, { "date": "20100817", "datequalifier": "38" } ], "NTE": [ { "refCode": "OTH", "desc": "No Touch" } ] }, { "Loop310": [ { "N1": { "idCode": "9998000006", "idQual": "ZZ", "name": "REDACTED", "entIdCode": "SF" }, "N3": [ { "address1": "REDACTED" } ], "G61": [ { "contactFunctionCode": "CN", "commNumber": "REDACTED", "commNumQualifier": "TE", "name": "REDACTED" } ], "N4": [ {} ] } ], "L11": [], "S5": { "stopReasonCode": "LD", "stopSeqNum": "2" }, "Loop350": [ { "LAD": [], "OID": { "poNum": "QWERTY", "refID": "ASDF", "unitMeasure": "PL", "quantity": "1" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "1", "desc": "PORT" } } ] } ], "AT5": [], "G62": [ { "date": "20100817", "datequalifier": "10" }, { "date": "20100817", "datequalifier": "38" } ], "NTE": [ { "refCode": "OTH", "desc": "Driver Count Required" } ] }, { "Loop310": [ { "N1": { "idCode": "9998000070", "idQual": "ZZ", "name": "PLACE", "entIdCode": "ST" }, "N3": [ { "address1": "PLACE" } ], "G61": [ { "contactFunctionCode": "CN", "commNumber": "XXXXXXXXXX", "commNumQualifier": "TE", "name": "X" } ], "N4": [ {} ] } ], "L11": [], "S5": { "stopReasonCode": "UL", "stopSeqNum": "3" }, "Loop350": [ { "LAD": [], "OID": { "poNum": "JOE", "refID": "SUPERMAN", "unitMeasure": "PL", "quantity": "1" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "1", "desc": "PORT" } } ] } ], "AT5": [], "G62": [ { "date": "20100817", "datequalifier": "68" }, { "date": "20100817", "datequalifier": "54" } ], "NTE": [ { "refCode": "OTH", "desc": "No Touch" } ] }, { "Loop310": [ { "N1": { "idCode": "0000403803", "idQual": "ZZ", "name": "REDACTED", "entIdCode": "ST" }, "N3": [ { "address1": "REDACTED" } ], "G61": [ { "contactFunctionCode": "CN", "commNumber": "0000000000", "commNumQualifier": "TE", "name": "REDACTED" } ], "N4": [ {} ] } ], "L11": [ { "qualifier": "DO", "refID": "THETHING" } ], "S5": { "stopReasonCode": "UL", "stopSeqNum": "4" }, "Loop350": [ { "LAD": [], "OID": { "weight": "161", "poNum": "UIP", "weightCode": "L", "unitMeasure": "CA", "refID": "JACK", "quantity": "6" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "1", "desc": "STUFF" } } ] }, { "LAD": [], "OID": { "weight": "104", "poNum": "JKLM", "weightCode": "L", "unitMeasure": "CA", "refID": "SUSAN", "quantity": "6" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "2", "desc": "STUFF" } } ] }, { "LAD": [], "OID": { "weight": "1833", "poNum": "ASDF", "weightCode": "L", "unitMeasure": "CA", "refID": "JOE", "quantity": "40" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "3", "desc": "STUFF" } } ] }, { "LAD": [], "OID": { "weight": "229", "poNum": "AAAA", "weightCode": "L", "unitMeasure": "CA", "refID": "ASDF", "quantity": "6" }, "Loop360": [ { "Loop365": [], "L5": { "lineNum": "4", "desc": "STUFF" } } ] } ], "AT5": [], "G62": [ { "date": "20100817", "datequalifier": "68" }, { "date": "20100817", "datequalifier": "54" } ], "NTE": [ { "refCode": "OTH", "desc": "Driver Assist Required" } ] } ], "SE": { "numSegments": "70", "controlNum": "0002" }, "Loop100BT": [], "L11": [ { "qualifier": "VD", "refID": "SALLY" }, { "qualifier": "SI", "refID": "MARK" }, { "qualifier": "CR", "refID": "JOE" }, { "qualifier": "RB", "refID": "USD" }, { "qualifier": "TH", "refID": "REDACTED" } ], "PLD": [], "L3": { "weight": "2328", "advances": "0", "rateQual": "FR", "charge": "05", "freightRate": "", "weightQual": "G", "quantity": "59" }, "B2": { "ordernum": "12345", "paymethod": "PP", "scac": "XXXX" }, "Loop100VI": [ { "N1": { "name": "REDACTED", "entIdCode": "AA" }, "G61": [ { "contactFunctionCode": "CN", "commNumber": "REDACTED", "contactReference": "0563", "commNumQualifier": "TE", "name": "REDACTED" }, { "contactFunctionCode": "IC", "commNumber": "REDACTED", "commNumQualifier": "EM", "name": "REDACTED" }, { "contactFunctionCode": "ZZ", "name": "REDACTED" } ] } ], "G62": [ { "date": "20100827", "timequalifier": "1", "datequalifier": "64", "time": "1302" } ], "Loop100CB": [], "NTE": [ { "refCode": "ZZZ", "desc": "26" }, { "refCode": "OTH", "desc": "No Touch" }, { "refCode": "OTH", "desc": "Driver Count Required" }, { "refCode": "OTH", "desc": "No Touch" }, { "refCode": "OTH", "desc": "Driver Assist Required" } ], "B2A": { "purpose": "00" }, "N7": [ { "equipLength": "4800", "equipHeight": "0", "weight": "2328", "equipWidth": "0", "equipNum": "ZZZZ", "equipType": "TV", "weightQual": "G" } ] } </pre></code></p> <p>Thanks, T.J.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload