Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

javascript - How to set table as Postman.variables object

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

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

1 Reply

0 votes
by (71.8m points)
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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...