spark85 / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

support escape \' in inline queries #71

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

{
    "logs": [
        {
            "message": "it's here",
            "id": 2
        }
    ]
}

I would like to extract the id by filtering the message. 

$.logs[?(@.message == 'it\'s here')]

Please use labels and text to provide additional information.

Original issue reported on code.google.com by kalle.st...@gmail.com on 11 Mar 2015 at 11:56

GoogleCodeExporter commented 9 years ago
Fixed in upcoming release. Note that you must use double escape characters.

      @Test
      public void issue_71() {
           String json = "{\n"
                + "    \"logs\": [\n"
                + "        {\n"
                + "            \"message\": \"it's here\",\n"
                + "            \"id\": 2\n"
                + "        }\n"
                + "    ]\n"
                + "}";

           List<String> result = JsonPath.read(json, "$.logs[?(@.message == 'it\\'s here')].message");

           Assertions.assertThat(result).containsExactly("it's here");
      }

Original comment by kalle.st...@gmail.com on 12 Mar 2015 at 12:49