Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to put table as new Postman variable, but I am probably doing something wrong with syntax, because when I try to used initialized table, there is "Unexpected token in JSON" error.

This is my initialization of table:

pm.variables.set("cr", {crypt_arr: [
{
    key: "BTC",
    used: false
},
{
   key: "ETH",
    used: false 
},
{
   key: "XRP",
    used: false 
}]});

This is how I use this table. Maybe there is something wrong there:

const crypto_arr = JSON.parse(pm.variables.get()).crypt_arr;
question from:https://stackoverflow.com/questions/65884098/how-to-set-table-as-postman-variables-object

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
234 views
Welcome To Ask or Share your Answers For Others

1 Answer

const crypto_arr = JSON.parse(pm.variables.get('cr')).crypt_arr;

you have to specify the variable name

Also you don't have to parse it as varible stored as object itself

   const crypto_arr = (pm.variables.get('cr')).crypt_arr;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...