从 tsung 中的 JSON 响应中提取数组元素,数组是响应的根
Extract array elements from a JSON response in tsung, array being the root of the response
我使用的是 tsung 1.6,我有一个配置文件,其中一个请求 return 以下响应。
响应:
[
{ key: value1 },
{ key: value2 }
]
我的目标是从响应中提取一些变量项并进一步使用它们。具体来说,我想在动态变量中提取 value1
和 value2
。以下是我正在做的
<request>
<dyn_variable name="value1" jsonpath="$[0].key"/>
<dyn_variable name="value2" jsonpath="$[1].key"/>
<http url='/get.json' version='1.1' method='GET'></http>
</request>
<request subst="true">
<http
url='/patch/%%_value1%%'
version='1.1'
contents='{"notified":true}'
content_type='application/json;charset=utf-8'
method='PATCH'
/>
</request>
以上没有给我任何信息。
$[0]
语法是我从 this 站点获取的。这在 tsung 文档中被引用,但是 tsung 还提到它实现了一个非常有限的 jsonpath 子集。
在提取以下数据方面需要帮助。
谢谢
例如
test.json:
[{"a":1},{"b":2}]
tsung.xml:
<request>
<dyn_variable name="Result" jsonpath="$.[0].a"/>
<http url='/test.json' version='1.1' method='GET'></http>
</request>
p.s。
test.json 文件格式不是 utf-8 bom
如何提取数据的几个例子:
<dyn_variable name="id_1" jsonpath="$.content.id"/>
<dyn_variable name="id_2" jsonpath="$.content.[0].id"/>
<dyn_variable name="id_3" jsonpath="$.content.forms.array[?title=test].id"/>
查看更多示例:
https://goessner.net/articles/JsonPath/index.html#e2
并实时查看:
https://jsonpath.com/
我使用的是 tsung 1.6,我有一个配置文件,其中一个请求 return 以下响应。
响应:
[
{ key: value1 },
{ key: value2 }
]
我的目标是从响应中提取一些变量项并进一步使用它们。具体来说,我想在动态变量中提取 value1
和 value2
。以下是我正在做的
<request>
<dyn_variable name="value1" jsonpath="$[0].key"/>
<dyn_variable name="value2" jsonpath="$[1].key"/>
<http url='/get.json' version='1.1' method='GET'></http>
</request>
<request subst="true">
<http
url='/patch/%%_value1%%'
version='1.1'
contents='{"notified":true}'
content_type='application/json;charset=utf-8'
method='PATCH'
/>
</request>
以上没有给我任何信息。
$[0]
语法是我从 this 站点获取的。这在 tsung 文档中被引用,但是 tsung 还提到它实现了一个非常有限的 jsonpath 子集。
在提取以下数据方面需要帮助。
谢谢
例如
test.json: [{"a":1},{"b":2}]
tsung.xml:
<request>
<dyn_variable name="Result" jsonpath="$.[0].a"/>
<http url='/test.json' version='1.1' method='GET'></http>
</request>
p.s。 test.json 文件格式不是 utf-8 bom
如何提取数据的几个例子:
<dyn_variable name="id_1" jsonpath="$.content.id"/>
<dyn_variable name="id_2" jsonpath="$.content.[0].id"/>
<dyn_variable name="id_3" jsonpath="$.content.forms.array[?title=test].id"/>
查看更多示例: https://goessner.net/articles/JsonPath/index.html#e2
并实时查看: https://jsonpath.com/