Escaping

2,875 views
Skip to first unread message

Martin Eigenbrodt

unread,
May 3, 2012, 7:51:38 AM5/3/12
to JsonPath
Hi all,

is there a way to escape Special characters in JsonPath. For exmpale
given the json:
{
"This.Is.Some.Valid.Key" :\"value"
}

How do I express the literal "." in JsonPath?


Regards,

Martin

Kalle Stenflo

unread,
May 3, 2012, 8:13:22 AM5/3/12
to json...@googlegroups.com
Hello,

you can use bracket notation in JsonPath

@Test
public void path_with_bracket_notation() throws Exception {
String json = "{\"foo.bar\": {\"key\": \"value\"}}";

Assert.assertEquals("value", JsonPath.read(json, "$.['foo.bar'].key"));
}

Cheers
Kalle

Martin Eigenbrodt

unread,
May 3, 2012, 8:17:42 AM5/3/12
to json...@googlegroups.com
Works great. Thanks for the fast response.

Regards,

Martin

sai reddy

unread,
Jul 31, 2016, 12:15:27 PM7/31/16
to JsonPath, martinei...@googlemail.com
Hello Martin,

I am having same problem as you , I am using Rest Assured library to test my Restful APIS. I have couple of fields with dot notation (like some.name). please see how my json looks

{
"id":"123"
"Art.Num"="532957578"
}
I am using below code to get value of the field "Art.Num"
String Json = when().get("myUrl").asString();

JsonPath json = new JsonPath(Json);
json.get("['Art.Num']");

But it fails with exception, Can not extract Num on null object.

hope someone can help me.
Reply all
Reply to author
Forward
0 new messages