Feature Request
I wonder if you have considered exposing the json object to Python in order to convert directly between Python dictionaries and json? This would be extremely useful for exposing C++ functions that take json obejcts. The type conversion should be possible via the pybind11 project (for example).
No, I have not considered this so far, and I have not been confronted with that usecase.
As an example, I have a simulation library where most high-level objects either can be serialized to/from json, or take a json object as constructor argument. To create a python interface, the most pythonic way would be to pass a dict. Pybind11 already provides dict functionality on the c++ side and one could perhaps do dict to string to json as a simple conversion. This request may be more appropriate at pybind11 which do include support for i.e the Eigen matrix library.
I understand that this might be a usecase. But I am not sure whether such a Python binding is something this library has to provide by itself. That said, I would like to discuss how other people think about this feature request.
I understand that this might be a usecase. But I am not sure whether such a Python binding is something this library has to provide by itself. That said, I would like to discuss how other people think about this feature request.
It's not generally built into the parent library. Traditionally there will be a python library, using oh something like Boost.Python to do the binding or whatever, and it will just depend on this library and on python and it builds the binding layer (generally statically built in, as it would be in this case). It's pretty easy to do overall and there are tons of python binding libraries to use (or use the low level API's, verbose though they may be).
It's not generally built into the parent library.
Thanks for clarifying. I though so, too. I tend to close this issue, because I see no tasks for this library, and I assume all this is possible with the current public interface.
and I assume all this is possible with the current public interface.
It is yep. :-)
You could of course make the binding library yourself, but I'd still expect it to be a different git repo altogether, but generally it's someone in the python community that makes the python bindings. :-)
Thanks, do close at will. For future reference, here's an example for pybind11 bindings for jsoncpp:
Thanks for sharing!
Hi. I would also be interested in having a pybind11 binding for nlohmann::json. @mlund have you ever completed your binding? Even if this isn't included as part of this library, it would be nice to contribute to a wrapper on the pybind11 side (e.g. they include a wrapper for Eigen types).
I made rudimentary bindings to python dictionaries, see here:
https://github.com/mlund/faunus/blob/master/src/pyfaunus.cpp#L46
I made a small package that allows automatic conversion from py::object to nlohmann::json
and the other way around: https://github.com/martinRenou/pybind_json
For those interested in python bindings, have you considered simply loading the various C / C++ modules you want to use in cython?
It saves a lot of time.
There has been some work in the official pybind organization: https://github.com/pybind/pybind11_json :)
Most helpful comment
There has been some work in the official pybind organization: https://github.com/pybind/pybind11_json :)