更换空手道中的JSON KEY
我需要将JSON发送到端点,但是我需要用变量替换密钥。
我有这个代码
.....
* def idJson = response.id
Given path <mypath>
And headers {Authorization: '#(auth)'}
And request read('classpath:myjson.json')
.....
myjson.json文件是
{ “一个”: { ... “ b”:false, “ C”:是的 },, “ D”: { '#(idjson)': { “钥匙”:[ ..... ..... 这是给出的 } } }
但是,该值在JSON中没有替换。当我执行请求时,我会看到JSON包含字符串“#(IDJSON)”,而不是变量的值。关于如何解决这个问题吗?
谢谢
I need to send a Json to an endpoint but I need to replace a key with a variable.
I've this code
.....
* def idJson = response.id
Given path <mypath>
And headers {Authorization: '#(auth)'}
And request read('classpath:myjson.json')
.....
The myjson.json file is
{
"a":
{
...
"b":false,
"c":true
},
"d":
{
'#(idJson)':
{
"Key":[
.....
]
}
}
}
But the value is not replace in the json. When I perform the request I see that the json contains the string '#(idJson)' instead of the value of the variable. Any idea about how to solve this?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嵌入式表达式不能用于修改JSON密钥。您必须使用这样的JS操作:
请注意,
d
可以这样替换,因此您仍然可以读取文件并保持动态:temp
可以是JSON,在阅读文件之前,在您的功能中定义。如果这太麻烦了,请贡献代码:)
Embedded expressions cannot be used to modify a JSON key. You have to use a JS operation like this:
Note that
d
could be replaced like this so you can still read the file and be dynamic:And
temp
can be JSON that is defined in your feature before reading the file.If this is too troublesome, please contribute code :)