How to genrate the property list inside the repeated loop?

Hello Team,

I am getting Json like format from my API. In that I need to create couple of list and property list using repeat loop.

Below code I tried using this i can able genrate the required list.
But how to genrated the property list inside the repeated loop? so that I can use for later validation

put [{“name”:“Test1”,“Age”:20,“depat”:“Eng”,“Loc”:“COB”,“Type”:“H”},{“name”:“Test2”,“Age”:30,“depat”:“Phy”,“Loc”:“KOR”,“Type”:“M”},{“name”:“Test3”,“Age”:25,“depat”:“Che”,“Loc”:“PUN”,“Type”:“S”}] into Test_list
log Test_list
set the listInsertionMode to “nested”

repeat with each item of Test_list
put it into inner_value
repeat with each item of inner_value
insert it.name into name
insert it.Age into Age
insert it.depat into depat
insert it.Loc into Loc
insert it.Type into Type
nsert “”&singlequote&it.rgrId&&singlequote&“:”&singlequote&it.rtyDesc&singlequote into Test
end repeat
end repeat
log name
log Age
log Loc
log Type
log “-----------------”
log Test
log “-----------------”

My excepectation of Test result should be:
{“Test1”:20,“Test2”:30,“Test3”:25,}

Hey Thanagaraj,

for the json return from an api you can use jsonvalue URL Transactions and Formatting | EPF Docs (eggplantsoftware.com)

Basically you want to have a list containing all values for the keys Test? into a new property list where the value of name is the new key?
you can use the following to print all keys values

put the name of each item of test_list 
put the age of each item of test_list

Cheers,
Karsten

I’m not sure I understand your intent, but this script gives the result you said you wanted, so perhaps it will give you an idea of how to get there:

put [{"name":"Test1","Age":20,"depat":"Eng","Loc":"COB","Type":"H"},{"name":"Test2","Age":30,"depat":"Phy","Loc":"KOR","Type":"M"},{"name":"Test3","Age":25,"depat":"Che","Loc":"PUN","Type":"S"}] into Test_list

set testAges to {}
repeat with each item of Test_list
	set testAges.(it.name) to it.age
end repeat

put testAges

This displays the result you asked for: {Test1:20, Test2:30, Test3:25}

1 Like