Skip to content

Instantly share code, notes, and snippets.

@navi2589
Created December 12, 2021 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navi2589/ecbd7a71db16c63eb0b23028e5d4ecb6 to your computer and use it in GitHub Desktop.
Save navi2589/ecbd7a71db16c63eb0b23028e5d4ecb6 to your computer and use it in GitHub Desktop.
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.ParseContext;
public class Solution {
private static final Configuration configuration = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
private static Configuration getConfiguration() {
return configuration;
}
private static ParseContext getParseContext() {
return JsonPath.using(getConfiguration());
}
public static void main(String[] args) {
DocumentContext documentContext = getParseContext().parse("{\"a\": 1,\"b\":2}");
System.out.println("reading json value of json attribute a " + documentContext.read("$.a"));
System.out.println("reusing documentContext to read json value of json attribute b " + documentContext.read("$.b"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment