1

I am using the karate java-api to work with Json objects. I have the below json to be created:

{
    "a": [
        {
            "b": [
                {
                    "c": "hello"
                }
            ]
        }
    ]
}

When I try to json.set("$.a[0].b[0].c", "hello"), I get the below error :

Exception in thread "main" java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.util.List (java.util.LinkedHashMap and java.util.List are in module java.base of loader 'bootstrap')
    at com.intuit.karate.Json.createPath(Json.java:232)
    at com.intuit.karate.Json.createPath(Json.java:246)
    at com.intuit.karate.Json.setInternal(Json.java:199)
    at com.intuit.karate.Json.set(Json.java:148)

The json path syntax is correct as cross checked, any other point(s) which I might be missing?

Edit: I'm using v1.1.0 of karate-core

1 Answer 1

1

Looks like a bug in Karate where so much array nesting is not supported. To replicate:

* def foo = {}
* set foo.a[0].b[0].c = 'hello'
* print foo

Since you were keen to contribute to Karate, maybe you can fix this :) Feel free to open an issue.

Here's the workaround:

* def foo = {}
* set foo.a[0].b = [{ c: 'hello' }]
* print foo
Sign up to request clarification or add additional context in comments.

2 Comments

never mind I opened an issue: github.com/karatelabs/karate/issues/1799
Thank you Peter :D The workaround which I am currently using is foo.a[0].b = []

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.