0


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
mayank bisht
  • 618
  • 3
  • 14
  • 43
  • Share your code what you have tried until now – Akshay May 28 '17 at 03:10
  • what is the requirement are you trying achieve? – Rajith Pemabandu May 28 '17 at 03:25
  • @RajithPemabandu :My requirement is to store all JSON node paths into list. Like this : $.shopper.Id $.shopper.Context.CollapseOrderItems $.shopper.Context.IsTest $.SelfIdentifiersData[0].SelfIdentifierData.SelfIdentifierType.SelfIdentifierType $.SelfIdentifiersData[1].SelfIdentifierData.SelfIdentifierType.SelfIdentifierType – mayank bisht May 28 '17 at 03:27
  • have you used the `JsonParser` class which is used in the post you have shared. – Rajith Pemabandu May 28 '17 at 03:34
  • @RajithPemabandu : Yes, I tried above mentioned tutorial , but i am getting **java.lang.NoClassDefFoundError: net/minidev/json/writer/JsonReaderI** exception. – mayank bisht May 28 '17 at 03:38
  • it would be helpful if you can post the full stack-trace. – Rajith Pemabandu May 28 '17 at 04:04
  • @RajithPemabandu :Added exception trace. – mayank bisht May 28 '17 at 04:10
  • From your error log it seems you are missing dependencies in your classpath – Akshay May 28 '17 at 04:14
  • @Akshay : yes, I tried adding missing jars into my project, but still throwing same exception. – mayank bisht May 28 '17 at 04:19
  • The best way to deal with classnotfound exception is try importing/atleast finding that class from the jar file..try doing that manually first..in that package net/minidev/json/writer/ there must be a class named JsonReaderI..if not try changing versions – Akshay May 29 '17 at 04:42

1 Answers1

1

Use this dependency for JsonReaderI. json-smart-2.1.0

ashwani46
  • 49
  • 6