Jackson JsonNode as input to JsonPath.read() not possible?

2,344 views
Skip to first unread message

Kevin Minder

unread,
Jul 17, 2013, 5:56:08 PM7/17/13
to json...@googlegroups.com
Can't seem to figure out an efficient way to evaluate a JsonPath against a Jackson JsonNode as it implements neither Map or List.  Any suggestions?

John Simpson

unread,
Jul 22, 2013, 11:20:11 PM7/22/13
to json...@googlegroups.com
I have the same question. For now, I simply convert the JsonNode to a String and then feed into the Json-Path. I'm sure it's not efficient at all. Look for some good suggestions.

Kevin Minder

unread,
Jul 23, 2013, 9:16:16 AM7/23/13
to json...@googlegroups.com
For now I'm using this other JsonPath package that works with Jackson.
https://github.com/nebhale/JsonPath
--
You received this message because you are subscribed to a topic in the Google Groups "JsonPath" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsonpath/LuUI8XTvczs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsonpath+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

bakos...@mind-era.com

unread,
Oct 28, 2014, 11:56:38 AM10/28/14
to json...@googlegroups.com
Hello,

   Sorry for resurrecting this old thread.
   I could not find a way to use Jackson (or JSR-353) either (I am using 1.1.0 version). I see there are com.jayway.jsonpath.spi.json.JsonProvider services -one of them is for Jackson-, but those are not exported (they are in the com.jayway.jsonpath.internal.spi.json internal package, but the service), nor qualified, so we cannot choose from them using the java.util.ServiceLoader. It seems there is something missing (I think from the META-INF/services should have files with SPI service implementations, the annotations on the service implementations to be able to select from them and preferably an OSGi service to be able to select the implementation of choice). Probably I do not understand how to use them. Can you help?
Thanks, gabor

PS.: I am try to use JsonPath from an OSGi R4 environment.

kalle stenflo

unread,
Oct 30, 2014, 1:56:38 PM10/30/14
to json...@googlegroups.com
Hi!

I don't know OSGi so I would appreciate some input here. I added the OSGi-plugin to the gradle build, that's all I have done. 

This is the generated manifest:

Manifest-Version: 1.0
Implementation-Title: json-path
Export-Package: 

com.jayway.jsonpath;version="1.1.1.SNAPSHOT";
   uses:="com.jayway.jsonpath.internal,com.jayway.jsonpath.spi.json,com.jayway.jsonpath.spi.mapper",
   
com.jayway.jsonpath.internal;version="1.1.1.SNAPSHOT";
   uses:="com.jayway.jsonpath,com.jayway.jsonpath.internal.token",

com.jayway.jsonpath.internal.spi.json;version="1.1.1.SNAPSHOT";
   uses:="com.fasterxml.jackson.databind,com.jayway.jsonpath,com.jayway.jsonpath.spi.json,net.minidev.json.writer",

com.jayway.jsonpath.internal.spi.mapper;version="1.1.1.SNAPSHOT";
   uses:="com.fasterxml.jackson.databind,com.jayway.jsonpath,com.jayway.jsonpath.spi.mapper",
   
com.jayway.jsonpath.internal.token;version="1.1.1.SNAPSHOT";
   uses:="com.jayway.jsonpath,com.jayway.jsonpath.internal,com.jayway.jsonpath.spi.json,com.jayway.jsonpath.spi.mapper",
   
com.jayway.jsonpath.spi.http;version="1.1.1.SNAPSHOT",com.jayway.jsonpath.spi.json;version="1.1.1.SNAPSHOT";
   uses:="com.jayway.jsonpath",com.jayway.jsonpath.spi.mapper;version="1.1.1.SNAPSHOT";uses:="com.jayway.jsonpath"
   
Bundle-SymbolicName: com.jayway.jsonpath.json-path
Bundle-Version: 1.1.1.SNAPSHOT
Implementation-Version: 1.1.1.SNAPSHOT
Bundle-Name: json-path
Bundle-ManifestVersion: 2
Bnd-LastModified: 1414515301000
Import-Package: com.fasterxml.jackson.core;version="[2.3,3)",com.faste
 rxml.jackson.databind;version="[2.3,3)",com.google.gson;version="[2.3
 ,3)",com.google.gson.internal;version="[2.3,3)",net.minidev.json;vers
 ion="[2.1,3)",net.minidev.json.parser;version="[2.1,3)",net.minidev.j
 son.writer,org.slf4j;version="[1.7,2)"
Created-By: 1.8.0_25 (Oracle Corporation)
Tool: Bnd-2.1.0.20130426-122213

bakos...@mind-era.com

unread,
Oct 30, 2014, 3:47:14 PM10/30/14
to json...@googlegroups.com
Hi,

   Interesting. In the 1.1.0 version the exported package part looks like this:
Export-Package: com.jayway.jsonpath;uses:="com.jayway.jsonpath.spi.mappe
 r,com.jayway.jsonpath.spi.json,org.slf4j,com.jayway.jsonpath.spi.http";
 version="1.1.0",com.jayway.jsonpath.spi.http;version="1.1.0",com.jayway
 .jsonpath.spi.json;uses:="com.jayway.jsonpath";version="1.1.0",com.jayw
 ay.jsonpath.spi.mapper;uses:="com.jayway.jsonpath";version="1.1.0"
This does not include the part for accessing com.jayway.jsonpath.internal.spi.json classes which would be required to change the defaults by direct class instantiation.
I was hoping the ServiceLoader can be used to access those classes, but it seems the SPI services are not properly exported in the released version either (from http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html):

If com.example.impl.StandardCodecs is an implementation of the CodecSet service then its jar file also contains a file named

 META-INF/services/com.example.CodecSet

This file contains the single line:

 com.example.impl.StandardCodecs    # Standard codecs
(But in the json-path-1.1.0.jar file I do not see META-INF/services folder.)
   This confused me how to access the implementation classes of com.jayway.jsonpath.spi.json.JsonProvider. Ideally something like this would be the best from the OSGi access perspective:

I'll try to find a way to add these kind of things to gradle during the weekend (though I have never used gradle before). If these kind of additions are welcome and I succeed, I'll send a pull request.
Thanks, gabor

PS.: Sorry for the bad English in my previous mail, I hope this time I made less mistakes.

bakos...@mind-era.com

unread,
Nov 5, 2014, 7:29:50 AM11/5/14
to json...@googlegroups.com
(Just a follow-up: Pull request has been sent to fix at least the SPI problem, OSGi should also be fixed, but for some reason I could not get a serviceReference. If others have an idea what might be a problem, comments, further commits are welcome. During testing I have found a possible bug with JacksonTreeJsonProvider.)

kalle stenflo

unread,
Nov 13, 2014, 4:54:54 PM11/13/14
to json...@googlegroups.com
From version 1.2.0 there is a new JsonProvider, the JacksonJsonNodeJsonProvider, that enables JsonNode based input and output.

Luigi Suardi

unread,
Dec 22, 2015, 10:39:57 AM12/22/15
to JsonPath
Hi Kalle,

I am looking for examples that show how to use JsonPath to query JsonNodes and get results back as JsonNodes.
As you mention below this should be covered by the JacksonJsonNodeJsonProvider.
Does it perform well? Some help getting started would be great.

Thank you!
Luigi
Reply all
Reply to author
Forward
0 new messages