JSON 101 Help

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
cf1flyboy
Newbie
Posts: 7
Joined: Thu Nov 17, 2016 4:21 pm

JSON 101 Help

Post by cf1flyboy » Thu Nov 17, 2016 4:37 pm

New to JSON and unable to get any results out of my test script
Seems like I am missing something simple, anyone have any ideas???

Code: Select all

/*
MyJSON:
{
"getallpricesresult": {
"items": {
"item": {
"itemid": "ItemA",
"description”: "Test Item A",
"upc": "1234567890123",
"currenteffectivedate": "9/1/2017"
"currentprice": "26.00",
"nexteffectivedate": "11/1/2017",
"nexteffectiveprice": "28.00"
}
"item": {
"itemid": "ItemB",
"description”: "Test Item B",
"upc": "1234567890124",
"currenteffectivedate": "9/1/2017"
"currentprice": "29.00",
"nexteffectivedate": "11/1/2017",
"nexteffectiveprice": "24.00"
}
"item": {
"itemid": "ItemC",
"description”: "Test Item C",
"upc": "1234567890125",
"currenteffectivedate": "9/1/2017"
"currentprice": "29.00",
"nexteffectivedate": "",
"nexteffectiveprice": ""
}
}
}
}
*/

LabelToVar>MyJSON,sJSON
JSONParse>sJSON,items,result1
JSONParse>sJSON,itemid,result2
JSONParse>sJSON,Item[2].UPC,result3

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: JSON 101 Help

Post by Marcus Tettmar » Mon Nov 21, 2016 8:23 pm

Well apart from the syntax of the JSONParse statement, that's not valid JSON. Arrays should be in [ ] and identifiers need to be unique so "item" is erroneous. You also have the wrong quote character after description and a missing comma after the currenteffectivedate value.

Here's the fixed up version and a working example to get the description values:

Code: Select all

/*
MyJSON:
{  
   "getallpricesresult":{  
      "items":[  
         {  
            "itemid":"ItemA",
            "description":"Test Item A",
            "upc":"1234567890123",
            "currenteffectivedate":"9/1/2017",
            "currentprice":"26.00",
            "nexteffectivedate":"11/1/2017",
            "nexteffectiveprice":"28.00"
         },
         {  
            "itemid":"ItemB",
            "description":"Test Item B",
            "upc":"1234567890124",
            "currenteffectivedate":"9/1/2017",
            "currentprice":"29.00",
            "nexteffectivedate":"11/1/2017",
            "nexteffectiveprice":"24.00"
         },
         {  
            "itemid":"ItemC",
            "description":"Test Item C",
            "upc":"1234567890125",
            "currenteffectivedate":"9/1/2017",
            "currentprice":"29.00",
            "nexteffectivedate":"",
            "nexteffectiveprice":""
         }
      ]
   }
}

*/


LabelToVar>MyJSON,sJSON
JSONParse>sJSON,getallpricesresult.items[0].description,res
JSONParse>sJSON,getallpricesresult.items[1].description,res
JSONParse>sJSON,getallpricesresult.items[2].description,res
Paste your version of the JSON into the validator/formatter here and it will give you a list of problems:
https://jsonformatter.curiousconcept.com/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

cf1flyboy
Newbie
Posts: 7
Joined: Thu Nov 17, 2016 4:21 pm

Re: JSON 101 Help

Post by cf1flyboy » Tue Nov 22, 2016 1:28 pm

THANKS!!!
That really helps,
Also the validation Web site will come in handy
:D

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts