mayank bisht
mayank bisht

Reputation: 618

Need explanation with this post


I want to save JSON path for each JSON node in a list.
I came across this tutorial :How do I get a list of all JSON paths to values from a JSON String? ,
but I am unable to understand & execute it
Please help..

Code:

String json = "{'shopper': {'Id': '4973860941232342', 'Context': {'CollapseOrderItems': false, 'IsTest': false } }, 'SelfIdentifiersData': {'SelfIdentifierData': [{'SelfIdentifierType': {'SelfIdentifierType': '111'} }, {'SelfIdentifierType': {'SelfIdentifierType': '2222'} } ] } }";

Configuration conf = Configuration.defaultConfiguration();
List<String> jsonPaths = JsonPath.using(conf).parse(json).read("$");

for (String path : jsonPaths) {
    System.out.println(path);
}

Expected Output:

$.shopper.Id
$.shopper.Context.CollapseOrderItems
$.shopper.Context.IsTest
$.SelfIdentifiersData[0].SelfIdentifierData.SelfIdentifierType.SelfIdentifierType
$.SelfIdentifiersData[1].SelfIdentifierData.SelfIdentifierType.SelfIdentifierType


Exception trace :

Exception in thread "main" java.lang.NoClassDefFoundError: net/minidev/json/writer/JsonReaderI
    at com.jayway.jsonpath.internal.DefaultsImpl.<init>(DefaultsImpl.java:17)
    at com.jayway.jsonpath.internal.DefaultsImpl.<clinit>(DefaultsImpl.java:15)
    at com.jayway.jsonpath.Configuration.getEffectiveDefaults(Configuration.java:53)
    at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:178)
    at com.json.JsonPathCreator.main(JsonPathCreator.java:17)
Caused by: java.lang.ClassNotFoundException: net.minidev.json.writer.JsonReaderI
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 5 more

Upvotes: 0

Views: 1613

Answers (1)

ashwani46
ashwani46

Reputation: 49

Use this dependency for JsonReaderI. json-smart-2.1.0

Upvotes: 1

Related Questions