JSONpath library to be used with jansson

1,249 views
Skip to first unread message

rogerz

unread,
Mar 10, 2012, 7:27:53 AM3/10/12
to jansson-users
Hi all,

I am looking for a JSONPath library to be used with jansson. It is listed in the Roadmap of jansson, saying 

> " These should probably be implemented as separate libraries to keep the Jansson core smaller. "

Could anybody recommend one such JSONPath implementation? In C language. I want to get a json object reference by 
    json_get_object(json, "store.book[0].title");
 ,---.  Rogerz Zhang
( @ @ ) Human, not octopus
 ).-.(  Chase what you love. Let the rest go.
'/|||\` Share > Google+ | Note > Tumblr | Random > twitter 微博
  '|`   AsciiArt < Shimrod(hh)

Jonathan Landis

unread,
Mar 10, 2012, 11:22:40 AM3/10/12
to jansso...@googlegroups.com
(2012年03月10日 04:27), rogerz wrote:
> *. I want to get a json object reference by

> json_get_object(json, "store.book[0].title");

To handle the problem of querying something inside a nested hierarchy, I
use a JSON array as the query string instead of Javascript-style
notation. So your example would become

json_get_object(json, "[\"store\", \"book\", 0, \"title\"]");

This way you can reuse the JSON parser for the query string, and your
implementation of the query function is really short and easy to read.
You just iterate over the array, getting the appropriate array element
or object property at each step, depending on whether you have a number
value or string value.

JKL

rogerz

unread,
Mar 10, 2012, 9:37:46 PM3/10/12
to jansso...@googlegroups.com
On Sun, Mar 11, 2012 at 12:22 AM, Jonathan Landis <jkla...@gmail.com> wrote:
(2012年03月10日 04:27), rogerz wrote:
*. I want to get a json object reference by

    json_get_object(json, "store.book[0].title");

To handle the problem of querying something inside a nested hierarchy, I use a JSON array as the query string instead of Javascript-style notation. So your example would become

json_get_object(json, "[\"store\", \"book\", 0, \"title\"]");

Thanks Jonathan. Have you already made such an extension to Jansson?

This looks easy to implement but not so friendly nor elegant to me. I guess I need to create another layer to translate the javascript-style notation to the json array.

Petri Lehtinen

unread,
Mar 11, 2012, 6:51:21 AM3/11/12
to jansso...@googlegroups.com
rogerz wrote:
> Hi all,
>
> I am looking for a JSONPath library to be used with jansson. It is listed in
> the Roadmap of jansson, saying
>
> > " These should probably be implemented as separate libraries to keep the
> Jansson core smaller."
>
> Could anybody recommend one such JSONPath implementation? In Clanguage.I want

> to get a json object reference by
>
> json_get_object(json, "store.book[0].title");

As far as I know, there are no JSONPath implementations for Jansson or
even the C language.

JSONPath is a bit problematic, as no accurate specification exists for
it. There's only a web page that explains one implementation and it
doesn't formally specify how identifiers should be parsed, for
example.

Petri

rogerz

unread,
Apr 9, 2012, 9:49:57 AM4/9/12
to jansso...@googlegroups.com
On Sun, Mar 11, 2012 at 6:51 PM, Petri Lehtinen <pe...@digip.org> wrote:
As far as I know, there are no JSONPath implementations for Jansson or
even the C language.

JSONPath is a bit problematic, as no accurate specification exists for
it. There's only a web page that explains one implementation and it
doesn't formally specify how identifiers should be parsed, for
example.

I have made a branch on jansson to implement the basic support for JSONPath. Please see my fork on GitHub for details:


---
rogerz

j...@flowroute.com

unread,
Jan 23, 2013, 12:42:42 PM1/23/13
to jansso...@googlegroups.com
On Monday, April 9, 2012 6:49:57 AM UTC-7, Rogerz Zhang wrote:

I have made a branch on jansson to implement the basic support for JSONPath. Please see my fork on GitHub for details:


---
rogerz

My company has decided to try this branch out, and it's been useful so far. Is there any hope of having it merged into the mainline?

-Joe H

Petri Lehtinen

unread,
Jan 23, 2013, 2:39:43 PM1/23/13
to jansso...@googlegroups.com
As I've said earlier, I'd rather like to see it as a separate library,
because most Jansson users don't need JSONPath support.

It seems to me that the code in rogerz's src/path.c doesn't really
depend on any important Jansson internals. It only uses the memory
management functions, and json_error_t and related internal functions,
but nothing that's really complicated. Thus it shouldn't be hard to
refactor it to be a separate standalone library.

Petri

Joe Hillenbrand

unread,
Jan 23, 2013, 3:42:06 PM1/23/13
to jansso...@googlegroups.com
Great idea! Why didn't I think of that?

Thank,

-Joe H


Reply all
Reply to author
Forward
0 new messages