Katalon Studio对象库中如何传递JSON数组内的完整JSON对象作为API参数
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 andMaps 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 (
name1instead ofpersonaName), Katalon can correctly replace each${placeholder}with your variable values.
Quick Checks to Ensure Success
- Double-check your test object's request body for syntax errors (missing brackets, unclosed quotes, etc.).
- 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

