Skip to content

JsonPath cannot create a new path if doesn't exists #570

Open
@pyus13

Description

@pyus13

Eg the Json is

val myJson = "properties" : {
}

val json = JsonPath.parse(myJson).set("$.properties.image.source", "my_image_url").jsonString()

Log.d("", "JSON UPDATED $json")

returns

"properties" : {
}

instead of

"properties" : {
    "image" :{
        "source" : "my_image_url" 
    }
}

The test method in Kotlin.

 @Test
 fun testJsonPathSet() {
        val jsonString = "{\"properties\": {}}"
        val newJson = JsonPath.parse(jsonString).set("$.properties.image.source", "image_url").jsonString()
        val expectedNewJson = "{\"properties\":{\"image\":{\"source\":\"image_url\"}}}"
        Assert.assertEquals(expectedNewJson, newJson)
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions