我想从 json 文件中提取数组

I want to extract array from json file

我有 json 个包含此数据的文件 [ { "rolename": "一号", “roledescription”:“一号”, “角色权限”:[“manage_users”,“view_user_logs”], “角色类型”:“客户”

} ]

我想从“rolepermission”中提取数据并将其放入正文请求中 这 api 接受这样的数据 {

“角色”:{

"name": "Test",

"description": "Test",

"permissions": [

    "manage_users",

    "manage_role",

    "managing_custom_page"

],

"userType":"admin"

} } 然后我将它转换成这个以从我的 json 文件中提取数据 {

“角色”:{

"name": "{{rolename}}",

"description": "{{roledescription}}",

"permissions": [

    "{{rolepermission}}"

],

"userType": "{{roletype}}"

} }

但是他这样发送请求

“权限”:[ “manage_users,view_user_logs” ],

相反,它应该像这样发送 “权限”:[ “manage_users”, “view_user_logs” ],

我该怎么办

要保存数组数据,首先需要stringify这里提到https://learning.postman.com/docs/sending-requests/variables/#understanding-variables

const res = pm.response.json();
const rolepermission = res.data[0].rolepermission;
pm.environment.set("rolepermission", JSON.stringify(rolepermission));

在请求正文中使用此变量:

{
  "role": {
    "name": "{{rolename}}",
    "description": "{{roledescription}}",
    "permissions": {{rolepermission}},
    "userType": "{{roletype}}"
  }
}