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

Hello Team,

Using above suggestion I have create the property list in repeated loop. But I am getting @ front of key. How to remove “@”?

my code

set costRate to {}
repeat for each item of validrgrID
log it
log “------------------------------”
set CostRateURL to “URL”
put sampleGet(url:CostRateURL) into CostRateResult
put JSONValue(CostRateResult.responseBody) into universal CostRateData
//put the rgrId of any item of universal CostRateData into rgrIdValue
//log rgrIdValue
put the svs of any item of universal CostRateData into svsValue
if svsValue is empty
put 0 into svsValue
end if
set costRate.(it) to svsValue
log costRate
end repeat

output:

1/8/24, 11:00:35 AM Log {@“1024429”:0.01, @“1024430”:1, @“1024431”:1, @“1026730”:0.01, @“1030250”:0.01, @“1032017”:120.5, @“1032423”:120.5, @“1032898”:0, @“1034326”:0, @“1034660”:120.5, @“1034661”:120.5, @“1034662”:120.5}

I would recommend that you insert a breakpoint and take a look in the Variable Watcher pane. I think that you will find the “@” symbols are not part of the data but rather display only in the log because of how property lists are rendered in log files.