You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Katalon Studio对象库中如何传递JSON数组内的完整JSON对象作为API参数

Fixing JSON Array Object Parameter Passing in Katalon Studio Test Objects

Got it, let's get this sorted out. The issue here is how you're structuring the personaForOrgTypeList parameter in your test case—you need to match the exact nested JSON structure the API expects, and align your parameter keys with the placeholders in your test object's request body.

Let's Break Down the Problem

Your target request body looks like this:

{ 
  "id":"${id}", 
  "personaForOrgTypeList": [
    {"id": "${id}","name1": "${name1}","alias":"${alias}"}
  ] 
}

But your current parameter for personaForOrgTypeList is a single map ([('personaName'):personaName,('alias'):personaAlias,('id'):personaid]) instead of a list containing a map (to match the array structure). Also, your key personaName doesn't match the placeholder ${name1} in the request body—this will prevent Katalon from replacing the value correctly.

The Corrected Approach

First, build a nested structure that mirrors the API's expected array-of-object format, then pass that as the parameter value. Here's how to adjust your code:

// Step 1: Create the nested object matching the API's array item structure
def personaItem = [
    'id': personaid,       // Matches ${id} in the array's object
    'name1': personaName,  // Matches ${name1} (note the key name matches the placeholder)
    'alias': personaAlias  // Matches ${alias}
]

// Step 2: Wrap it in a list to match the personaForOrgTypeList array
def personaList = [personaItem]

// Step 3: Pass the parameters to your test object
responseObj = WS.sendRequest(findTestObject(
    'Object Repository/API/Organization/POST_for_organizationLevelWithValidPersonaNoParent',
    [
        ('id'): id,
        ('personaForOrgTypeList'): personaList
    ]
))

Why This Works

  • Katalon automatically converts Groovy Lists to JSON arrays and Maps to JSON objects, so this structure will translate exactly to the array-of-object format your API needs.
  • By using keys that exactly match the placeholders in your test object's request body (name1 instead of personaName), Katalon can correctly replace each ${placeholder} with your variable values.

Quick Checks to Ensure Success

  1. Double-check your test object's request body for syntax errors (missing brackets, unclosed quotes, etc.).
  2. After running the test, check the request logs in Katalon to verify the actual sent body matches your target structure. You can use WS.getRequestContent(responseObj) to print the final request body for debugging.

内容的提问来源于stack exchange,提问作者swati sachan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 14:22:38