Package com.jayway.jsonpath

Examples of com.jayway.jsonpath.JsonPath


    }

    @Test
    public void read_store_book_1() throws Exception {

        JsonPath path = JsonPath.compile("$.store.book[1]");

        Map map = path.read(DOCUMENT);

        assertEquals("Evelyn Waugh", map.get("author"));
    }
View Full Code Here


        assertEquals("Evelyn Waugh", map.get("author"));
    }

    @Test
    public void read_store_book_wildcard() throws Exception {
        JsonPath path = JsonPath.compile("$.store.book[*]");

        List<Object> list = path.read(DOCUMENT);
        Assertions.assertThat(list.size()).isEqualTo(4);

    }
View Full Code Here

    @Path("/validate")
    @Produces(MediaType.APPLICATION_JSON)
    public Response validate(@QueryParam("path") String path) {
        int result = -1;
        try {
            JsonPath compiled = JsonPath.compile(path);
            result = compiled.isDefinite() ? 0 : 1;
        } catch (Exception e) {
        }
        return Response.ok(Collections.singletonMap("result", result)).build();
    }
View Full Code Here

  }

  public SpinJsonTreePathQuery jsonPath(String expression) {
    ensureNotNull("expression", expression);
    try {
      JsonPath query = JsonPath.compile(expression);
      return new SpinJsonJacksonPathQuery(this, query, dataFormat);
    } catch(InvalidPathException pex) {
      throw LOG.unableToCompileJsonPathExpression(expression, pex);
    } catch(IllegalArgumentException aex) {
      throw LOG.unableToCompileJsonPathExpression(expression, aex);
View Full Code Here

  public static void main(String... args) throws Exception {

    RestTemplate template = new RestTemplate();
    String response = template.getForObject(URI_TEMPLATE, String.class, MILESTONE_ID);

    JsonPath titlePath = JsonPath.compile("$[*].title");
    JsonPath idPath = JsonPath.compile("$[*].number");

    JSONArray titles = titlePath.read(response);
    Iterator<Object> ids = ((JSONArray) idPath.read(response)).iterator();

    System.out.println("Milestone - " + JsonPath.read(response, "$[1].milestone.title"));

    for (Object title : titles) {

View Full Code Here

    public void writeValue(String jsonPathExpression, Object value) {
        PlainJavaJsonProvider provider = new PlainJavaJsonProvider();
        Configuration configuration = Configuration.builder().jsonProvider(provider).build();
        jsonObject = provider.parse(currentJson);
        JsonPath path = JsonPath.compile(jsonPathExpression);
        LinkedList<PathToken> pathTokens = getPathTokensFrom(path);
        PathToken endToken = pathTokens.removeLast();
        int index = pathTokens.size();
        JsonWriteDecorator writeDecorator = new JsonWriteDecorator(provider, index, endToken, value);
        pathTokens.addLast(writeDecorator);
        path.read(jsonObject, configuration);
        jsonObject = MutableValue.FROM_MUTABLE_VALUE.apply(jsonObject);
        currentJson = buildJsonStringFrom(jsonObject);
    }
View Full Code Here

    }

    public <T> T readObjectValue(String jsonPathExpression) {
        PlainJavaJsonProvider provider = new PlainJavaJsonProvider();
        Configuration configuration = Configuration.builder().jsonProvider(provider).build();
        JsonPath jsonPath = JsonPath.compile(jsonPathExpression);
        return jsonPath.read(jsonObject, configuration);
    }
View Full Code Here

TOP

Related Classes of com.jayway.jsonpath.JsonPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.