Hi,
I need to extract the name value from json path. Always the path wont be available sometimes entity will be blank, so if the entity is blank then i need to pass “”.
.check(jsonPath("$.entity.name").exists.saveAs("name")) but this will fail if I use .check(jsonPath("$.entity.name"").notExists.saveAs("name")) this will pass only if it is not available.
I couldnt implement the doIfEqualsOrElse in check I am finding difficulties.
Hi @sbrevet
Currently, am using optional
.check(jsonPath(“$.entity.name”).optional.saveAs(“name”))
But I also need to pass “” if the json path doesn’t find $.entity.name , for which optional doesn’t declare the attribute and the #{name} attribute will be undefined
.check(jsonPath(“$._entity.name”).withDefault(“""”).optional.saveAs(“name”)) – this code will help me fetch name if available or else default will be “” which solved
But I also need to append/concatenate the names within quotes “abc” which I am doing via below code. Any better solutions with transform and mkstring ?
.exec(session => {session.set(“name”, “"”+session(“name”).as[String]+“"”)})