jsonparse with Spaces in Keys

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
glavender
Newbie
Posts: 10
Joined: Thu Aug 21, 2014 7:20 pm

jsonparse with Spaces in Keys

Post by glavender » Tue Mar 08, 2016 6:57 pm

I have json string that has some keys with spaces. The following works because the key has no spaces (Sym1):

JSONParse>HTMLResponse,dataset.ZoneYC.Sym1,theHigh

The following errors with access violation with key having spaces (NQ - NQ11)

JSONParse>HTMLResponse,dataset.ZoneYC.NQ - NQ11,theHigh

I also tried these formats:
JSONParse>HTMLResponse,dataset.ZoneYC['NQ - NQ11'],theHigh
JSONParse>HTMLResponse,dataset.ZoneYC['"NQ - NQ11"'],theHigh
JSONParse>HTMLResponse,dataset.ZoneYC["NQ - NQ11"],theHigh

Is there a way to for JSONParse to read json strings with keys containing spaces?
Thank you,
Gerry

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: jsonparse with Spaces in Keys

Post by JRL » Thu Mar 10, 2016 2:07 pm

Using the JSONParse> sample from help and changing the "clients" key to "all clients", I can confirm that JSONParse> fails with an Access Violation error if there is a space in the key name. Sounds like something will need to be fixed to be able to use spaces.

Code: Select all

/*
MyJSON:
{ "uid" : "1234", 
  "all clients" : ["client1","client2","client3"],
  "people" : [{"Name":"Marcus","Age":"21"},{"Name":"Dorian","Age":"18"}],
  "color" : "red",
  "size" : 14 }
*/
 
LabelToVar>MyJSON,sJSON
 
JSONParse>sJSON,uid,result
JSONParse>sJSON,all clients,result
JSONParse>sJSON,all clients[1],result
JSONParse>sJSON,people[1].Name,result

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

Re: jsonparse with Spaces in Keys

Post by Marcus Tettmar » Fri Mar 11, 2016 3:16 pm

Thanks for this. Will look into it.

In the mean time a workaround would be to use StringReplace on the JSON string to change the items with spaces to e.g. underscores.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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