JSONParse number of strings in a branch?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

JSONParse number of strings in a branch?

Post by Grovkillen » Thu Jan 25, 2018 9:00 am

Given the example found in the help I cannot find any way of knowing how many (for example) names there is.I now need to parse until I get a blank return of the parse. Is there a way of getting the JSON path logically?

Or is a enhancement command "JSONpath" needed? I guess the same goes with XML.

Code: Select all

/*
MyJSON:
{ "uid" : "1234", 
  "clients" : ["client1","client2","client3"],
  "people" : [{"Name":"Marcus","Age":"21"},{"Name":"Dorian","Age":"18"},{"Name":"Grovkillen","Age":"99"}],
  "color" : [{"Name":"red", "RGB":"255,0,0"},{"Name":"green", "RGB":"0,255,0"},{"Name":"blue", "RGB":"0,0,255"}],
  "size" : 14 }
*/
 
LabelToVar>MyJSON,sJSON

Let>k=0
Repeat>k
  JSONParse>sJSON,people[%k%].Name,result
  If>result=
    Let>k=k-1
    MDL>Last "people.Name" is %k%!
    Let>k=-1
  Endif>
  Let>k=k+1
Until>k=0
Let>ME=%Script%

Running: 15.0.24
version history

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