使用 JsonPath 更新数组元素

flo*_*ind 5 arrays replace element jsonpath

我正在尝试使用 Java 中的 jayway 的 JsonPath 替换 Json 数组中的某个元素。例子:

{
"store": {
    "book": [
        {
            "category": "reference",
            "author": "Nigel Rees",
            "title": "Sayings of the Century",
            "price": 8.95
        },
        {
            "category": "fiction",
            "author": "Evelyn Waugh",
            "title": "Sword of Honour",
            "price": 12.99
        },
        {
            "category": "fiction",
            "author": "Herman Melville",
            "title": "Moby Dick",
            "isbn": "0-553-21311-3",
            "price": 8.99
        },
        {
            "category": "fiction",
            "author": "J. R. R. Tolkien",
            "title": "The Lord of the Rings",
            "isbn": "0-395-19395-8",
            "price": 22.99
        }
    ],
    "bicycle": {
        "color": "red",
        "price": 19.95
    }
},
"expensive": 10
Run Code Online (Sandbox Code Playgroud)

}

在这里,我希望能够替换数组中的第一本书。我可以使用此查询找到该元素$.store.book.[?(@.author =='Nigel Rees')]

然后我使用此代码替换此节点:

         Configuration configuration =  Configuration.builder()
           .jsonProvider(new JacksonJsonNodeJsonProvider())
           .mappingProvider(new JacksonMappingProvider())
           .build();
        DocumentContext pbContext = JsonPath.using(configuration).parse(theAboveJson);
        pbContext.set("$.store.book.[?(@.author =='Nigel Rees')]", someOtherJson);
Run Code Online (Sandbox Code Playgroud)

但我注意到,新节点没有替换,而是插入到 books 数组的位置 0 处。有没有办法实际替换数组元素?