Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jq needs a library! #98

Closed
nicowilliams opened this issue Apr 3, 2013 · 13 comments
Closed

jq needs a library! #98

nicowilliams opened this issue Apr 3, 2013 · 13 comments

Comments

@nicowilliams
Copy link
Contributor

A C library for jq would. be. awesome. Ditto Python, node/JS, ..., but a C library should be easier given that jq is already written in C.

This is really like XSLT/XPath for JSON, and simplified a great deal. I can do things with jq in a few characters that require multiple lines of Python/whatever, so I'm starting to resort to popen(). A library would be easier to use :)

@nicowilliams
Copy link
Contributor Author

This is a bit of a dup of #12 :(

@nicowilliams
Copy link
Contributor Author

This might not be so difficult... Looking at main.c the internals look very much like a decent API. The one issue is that there's some global state that needs to be moved into a context handle in order to make the API thread-safe and re-entrant. These are the global variables used to hold state outside of main.c:

cbuiltins
function_list
data_stk
fork_stk
frame_stk
pathbuf
pathsize

@nicowilliams
Copy link
Contributor Author

See pull request #109.

@stedolan
Copy link
Contributor

stedolan commented May 5, 2013

Thank you! I'd definitely intended to get around to doing this at some point, glad that someone else has beaten me to it :)

That looks like the right list of global variables, except cbuiltins can stay global (it's readonly and should be marked const). I haven't gotten around to reading through your pull rq yet, but at first glance it looks good.

stedolan added a commit that referenced this issue May 5, 2013
This means the .data and .bss sections are empty, a good thing
in a shared library (see #98).
@stedolan stedolan closed this as completed May 6, 2013
@icholy
Copy link

icholy commented Jun 13, 2013

@stedolan with the current autotools setup, is it still possible to build as a library?

@nicowilliams
Copy link
Contributor Author

with the current autotools setup, is it still possible to build as a library?

No, there's no trace of it left. I've been meaning to find time to
implement the library API we've talked about.

@icholy
Copy link

icholy commented Jun 14, 2013

@nicowilliams that would be very much appreciated. I'm looking to write bindings for Go.

@progrium
Copy link

+1 +1 +1 Especially @icholy on the Go bindings.

@netsgnut
Copy link

@dtolnay, should this be reopened or a new issue to be created instead? Thanks!

@dtolnay
Copy link
Member

dtolnay commented Aug 17, 2015

A library exists already. For example jq.py is built on it. The documentation is lacking but see C API: libjq for what is exported and public.

@netsgnut
Copy link

Oops my bad, didn't realize we now have a binding library now. Thanks for the pointer.

@nicowilliams
Copy link
Contributor Author

Until we have good docs I wouldn't say that the API is stable, though we're unlikely to make backwards-incompatible changes, really.

@nicowilliams
Copy link
Contributor Author

Also, if someone sends a PR with docs for the API...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants