簡體   English   中英

json 的顛簸變換 - 如何為 null 值添加移位操作

[英]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" != 10not 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM