Saving Nested JSON Response (Parent and Child Record) From Web Server To Topspeed or any file type structure

Hello Guys,

I am currently creating a simple REST Web Service using NetTalk.

I have created a request that will send this response formatted on JSON for example:

{
    "shoppingcart_response": {
        "shopcarthdr": [
            {
                "cartid": "2105218IEG1HYJ",
                "userid": "",
                "sellerid": "2008196195",
                "street": "29 Jump Street",
                "entrytype": "O",
                "receivername": "Juan Dela Cruz",
                "contactno": "n/a",
                "emailaddress": "[email protected]",
                "cartstatus": "X",
                "shopcartdtl": [
                    {
                        "cartid": "2105218IEG1HYJ",
                        "sellerid": "2008196195",
                        "productcode": "FAST000003",
                        "productprice": 11.5,
                        "taxcode": 0,
                        "qty": 200,
                        "detailtype": ""
                    },
                    {
                        "cartid": "2105218IEG1HYJ",
                        "sellerid": "2008196195",
                        "productcode": "Z_DELIVERYCHARGE",
                        "productprice": 0,
                        "taxcode": 0,
                        "qty": 1,
                        "detailtype": "D"
                    }
                ]
            },
            {
                "cartid": "210521DRVF9Q5O",
                "userid": "",
                "sellerid": "2008196195",
                "street": "29 Jump Street",
                "entrytype": "O",
                "receivername": "Juan Dela Cruz",
                "contactno": "n/a",
                "emailaddress": "[email protected]",
                "cartstatus": "X",
                "shopcartdtl": [
                    {
                        "cartid": "210521DRVF9Q5O",
                        "sellerid": "2008196195",
                        "productcode": "EGSCIBREAD013",
                        "productprice": 20,
                        "taxcode": 0,
                        "qty": 5,
                        "detailtype": ""
                    },
                    {
                        "cartid": "210521DRVF9Q5O",
                        "sellerid": "2008196195",
                        "productcode": "EGSCIBREAD014",
                        "productprice": 20,
                        "taxcode": 0,
                        "qty": 3,
                        "detailtype": ""
                    },
                    {
                        "cartid": "210521DRVF9Q5O",
                        "sellerid": "2008196195",
                        "productcode": "EGSCIEGG001",
                        "productprice": 195,
                        "taxcode": 0,
                        "qty": 1,
                        "detailtype": ""
                    },
                    {
                        "cartid": "210521DRVF9Q5O",
                        "sellerid": "2008196195",
                        "productcode": "EGSCIMEAT00011",
                        "productprice": 75,
                        "taxcode": 0,
                        "qty": 1,
                        "detailtype": ""
                    },
                    {
                        "cartid": "210521DRVF9Q5O",
                        "sellerid": "2008196195",
                        "productcode": "FAST000002",
                        "productprice": 23,
                        "taxcode": 1,
                        "qty": 1,
                        "detailtype": ""
                    },
                    {
                        "cartid": "210521DRVF9Q5O",
                        "sellerid": "2008196195",
                        "productcode": "SARANGANI2600",
                        "productprice": 212.8,
                        "taxcode": 0,
                        "qty": 1,
                        "detailtype": ""
                    },
                    {
                        "cartid": "210521DRVF9Q5O",
                        "sellerid": "2008196195",
                        "productcode": "Z_DELIVERYCHARGE",
                        "productprice": 0,
                        "taxcode": 0,
                        "qty": 1,
                        "detailtype": "D"
                    }
                ]
            },
            {
                "cartid": "210521YGWLKGG6",
                "userid": "",
                "sellerid": "2008196195",
                "street": "905 Aurora Blvd. Cor. Harvard",
                "entrytype": "O",
                "receivername": "Juan Dela Cruz",
                "contactno": "n/a",
                "emailaddress": "[email protected]",
                "cartstatus": "X",
                "shopcartdtl": [
                    {
                        "cartid": "210521YGWLKGG6",
                        "sellerid": "2008196195",
                        "productcode": "SUYHSUR13",
                        "productprice": 87,
                        "taxcode": 1,
                        "qty": 2,
                        "detailtype": ""
                    },
                    {
                        "cartid": "210521YGWLKGG6",
                        "sellerid": "2008196195",
                        "productcode": "Z_DELIVERYCHARGE",
                        "productprice": 0,
                        "taxcode": 1,
                        "qty": 1,
                        "detailtype": "D"
                    }
                ]
            }
        ],
        "skippedrecords": "0",
        "resultcomplete": "1"
    }
}

Based on the JSON response above, I have created a nested json structure, using shopcarthdr (as parent), and shopcartdtl (as child).

On the Client part(API Requester App that I created):
What I want to achieve is to load the shopcartdtl (child JSON values) to a separate table (topspeed file) since loading the header JSON to a file structure can be achieved using the load function from jFiles.

I already read jFiles document regarding loading nested JSON but I am confused with the explanation from the document.

Can someone help me in that?

Thanks in advanced.

Check out www.capesoft.com/jfilescode.

Paste your JSON in the text control and watch the magic happen.

2 Likes

I never thought that capesoft has that useful tool on their site. I have checked it and understand more of copying nested JSON files to Queue.

However, my only problem is how to copy queue with type attribute to a file.

shoppingcart_response    Group,Name('shoppingcart_response')
shopcarthdr                &shopcarthdrQueueType,Name('shopcarthdr | queue')
skippedrecords             STRING(255),Name('skippedrecords')
resultcomplete             STRING(255),Name('resultcomplete')
                         End
shopcarthdrQueueType      Queue,Type,Name('shopcarthdr')
cartid                     STRING(255),Name('cartid')
userid                     STRING(255),Name('userid')
sellerid                   STRING(255),Name('sellerid')
street                     STRING(255),Name('street')
entrytype                  STRING(255),Name('entrytype')
receivername               STRING(255),Name('receivername')
contactno                  STRING(255),Name('contactno')
emailaddress               STRING(255),Name('emailaddress')
cartstatus                 STRING(255),Name('cartstatus')
shopcartdtl                &shopcartdtlQueueType,Name('shopcartdtl | queue')
                         End

shopcartdtlQueueType      Queue,Type,Name('shopcartdtl')
cartid                     STRING(255),Name('cartid')
sellerid                   STRING(255),Name('sellerid')
productcode                STRING(255),Name('productcode')
productprice               Real,Name('productprice')
taxcode                    Real,Name('taxcode')
qty                        Real,Name('qty')
detailtype                 STRING(255),Name('detailtype')
                         End

Can you help me with that?

Thanks.

www.capesoft.com/jfilescode should have given you a method to save the JSON.

Something like:

json.Start()
json.SetTagCase(jf:CaseAsIs)
json.Save(element,st)

Also, I recommend watching yesterday’s ClarionLive open webinar where Bruce demonstrates how to add records to TYPE’d queues and save to JSON.

Starts at 49:15.

Thank you for this. but I forgot to say that I want to save the queue in a file structure like topspeed. For now I only know that saving records from queue, you must do a loop from the queue and then do the ADD method to the file. However, queue type files can’t do the same thing.

What I really want to achieve is to save JSON nested response coming from a web server, to a topspeed file with separate tables for the parent and child files(shopcardhdr as the parent and shopcartdtl as the child). Having a knowledge doing that can also be applicable to every other file structure types(like MySQL, MSSQL, etc.)

Another useful information you provide will be so much appreciated.

Thank you in advanced.

jFiles2 can save to table/file.

https://capesoft.com/docs/jfiles2/jfiles.htm#SavingJsonfile