[英]Jolt transformation of json - how to add shift operation for null value
我有三個場景:
場景 1:當"testInt" == 10
時, "isTrue"
應設置為false
, "testInt"
" 應設置為0
, "testString"
保持原樣。
輸入
{
"testString" :"testValue",
"testInt": 10,
"isTrue": true
}
預期 output
{
"testString" :"testValue",
"testInt": 0,
"isTrue": false
}
場景 2:當"testInt" == null
時, "testInt"
應該被刪除,其他的應該被刪除。
輸入
{
"testString" :"testValue",
"testInt": null,
"isTrue": true
}
預期 output
{
"testString" :"testValue",
"isTrue": true
}
場景 3:當"testInt" != 10
( not null
)時,沒有變化。
輸入
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
預期 output
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
如果有人建議我如何通過顛簸操作來實現這些,那將會很有幫助。
您可以將這種shift
操作與default
操作一起定義,以便能夠通過"null"
到null
轉換來處理null
案例
[{
"operation": "default",
"spec": {
"testInt": "null"
}
},{
"operation": "shift",
"spec": {
"testString": "testString",
"testInt": {
"10": {
"#0": "testInt"
},
"null": null,
"*": {
"@(2,testInt)": "testInt"
}
},
"isTrue": {
"@(2,testInt)": {
"10": {
"#false": "isTrue"
},
"*": {
"@(3,isTrue)": "isTrue"
}
}
}
}
}]
其中@(integer,key)
,例如"@(2,testInt)"
或"@(3,isTrue)"
表示開始搜索作為第二個參數呈現的所需鍵的級別。 這可以通過計算"spec": {
除了第一個{
in "spec": {
spec": { 之后的左花括號來計算。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.