英文:
Karate unable to set value for json
问题
我正在使用Karate为负载设置值。我的测试数据之一包含以avro命名空间格式命名的键。对于这种特殊情况,我无法设置该值
- def payload = { "name": { "com.val.str": "" } }
- set payload.name["com.val.str"] = 'hello'
- print payload
错误
```只能添加到数组```
我尝试过多种方式,如
- set payload.name[com.val.str] = 'hello'
- set payload.name.["com.val.str"] = 'hello'
然而,都没有起作用。
英文:
I'm using Karate set value for a payload. One of my test data contains a key name in avro namespace format. For this specific case, I'm unable to set the value
* def payload = { "name" : { "com.val.str": ""} }
* set payload.name["com.val.str"] = 'hello'
* print payload
Error
Can only add to an array
I tried multiple things like
* set payload.name[com.val.str] = 'hello'
* set payload.name.["com.val.str"] = 'hello'
However, nothing worked.
答案1
得分: 1
不使用 set
,只需记住普通的JS表达式即可:
* def payload = { "name": { "com.val.str": "" } }
* payload.name['com.val.str'] = 'hello'
* match payload == { name: { 'com.val.str': 'hello' } }
英文:
Don't use set
, just keep in mind that normal JS expressions work:
* def payload = { "name": { "com.val.str": "" } }
* payload.name['com.val.str'] = 'hello'
* match payload == { name: { 'com.val.str': 'hello' } }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论