Discussion:
[Rcpp-devel] Manipulating json with Rcpp
Neal Fultz
2018-10-11 18:50:46 UTC
Permalink
Hi all,

I recently needed to deal with json on the C++ side of things, and found
the nlohmann json library.

I made a small wrapper package: https://github.com/nfultz/RcppJson

I was pleasantly surprised how easy it was to make a header-only package
(by cannabalizing BH and copying the hpp file to inst/include).

Maybe someone else will find this useful some day.


Best,

Neal Fultz
Dirk Eddelbuettel
2018-10-11 19:18:04 UTC
Permalink
On 11 October 2018 at 11:50, Neal Fultz wrote:
| I recently needed to deal with json on the C++ side of things, and found
| the nlohmann json library.
|
| I made a small wrapper package: https://github.com/nfultz/RcppJson

Cool.

| I was pleasantly surprised how easy it was to make a header-only package
| (by cannabalizing BH and copying the hpp file to inst/include).

Why? Is LinkingTo: BH not good enough?
|
| Maybe someone else will find this useful some day.

There are also R (at least) cpp-using package ndjson and validatejsonr on CRAN.

Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Neal Fultz
2018-10-11 20:43:44 UTC
Permalink
(Resending to list, sorry)

| I was pleasantly surprised how easy it was to make a header-only package
Post by Dirk Eddelbuettel
| (by cannabalizing BH and copying the hpp file to inst/include).
Why? Is LinkingTo: BH not good enough?
I'm not using Boost for json, instead using this
https://nlohmann.github.io/json/ for the
syntax sugar.

But I wanted to start with something that was working instead of starting
from scratch, in case
there were package configuration that had to be set to make //
[[Rcpp::depends(RcppJson)]]
compile correctly. But Rcpp::depends seems to find everything
automatically, it "just works".
Post by Dirk Eddelbuettel
| Maybe someone else will find this useful some day.
There are also R (at least) cpp-using package ndjson and validatejsonr on CRAN.
Those are good finds. Not sure if you can use them from inside C++ though.

It looks like Bob Rudis is also using the nlohmann/json.h, maybe I can ask
him to
move json.h from src/ to inst/include for his next release. I think that's
all that needed
to make Rcpp::depends / LinkingTo work.
Post by Dirk Eddelbuettel
| I recently needed to deal with json on the C++ side of things, and found
| the nlohmann json library.
|
| I made a small wrapper package: https://github.com/nfultz/RcppJson
Cool.
| I was pleasantly surprised how easy it was to make a header-only package
| (by cannabalizing BH and copying the hpp file to inst/include).
Why? Is LinkingTo: BH not good enough?
|
| Maybe someone else will find this useful some day.
There are also R (at least) cpp-using package ndjson and validatejsonr on CRAN.
Dirk
--
Dirk Eddelbuettel
2018-10-11 23:55:05 UTC
Permalink
On 11 October 2018 at 13:43, Neal Fultz wrote:
| (Resending to list, sorry)
|
| | I was pleasantly surprised how easy it was to make a header-only package
| > | (by cannabalizing BH and copying the hpp file to inst/include).
| >
| > Why? Is LinkingTo: BH not good enough?
| >
|
| I'm not using Boost for json, instead using this
| https://nlohmann.github.io/json/ for the
| syntax sugar.

Ok, clearer now what you meant. And yes -- a good header-only JSON solution.

| But I wanted to start with something that was working instead of starting
| from scratch, in case
| there were package configuration that had to be set to make //
| [[Rcpp::depends(RcppJson)]]
| compile correctly. But Rcpp::depends seems to find everything
| automatically, it "just works".

Are you mostly using sourceCpp() ? Else use the package you created, and
have other package use LinkingTo: to it.

| > | Maybe someone else will find this useful some day.
| >
| > There are also R (at least) cpp-using package ndjson and validatejsonr on
| > CRAN.

Fair points. I was extrapolating because the last one I heard about what the
JSON modifier (not on CRAN yet) which works at the C++ level:

https://github.com/SymbolixAU/jsonify

| Those are good finds. Not sure if you can use them from inside C++ though.
|
| It looks like Bob Rudis is also using the nlohmann/json.h, maybe I can ask
| him to
| move json.h from src/ to inst/include for his next release. I think that's
| all that needed
| to make Rcpp::depends / LinkingTo work.

Yep!

Dirk


| On Thu, Oct 11, 2018 at 12:18 PM Dirk Eddelbuettel <***@debian.org> wrote:
|
| >
| > On 11 October 2018 at 11:50, Neal Fultz wrote:
| > | I recently needed to deal with json on the C++ side of things, and found
| > | the nlohmann json library.
| > |
| > | I made a small wrapper package: https://github.com/nfultz/RcppJson
| >
| > Cool.
| >
| > | I was pleasantly surprised how easy it was to make a header-only package
| > | (by cannabalizing BH and copying the hpp file to inst/include).
| >
| > Why? Is LinkingTo: BH not good enough?
| > |
| > | Maybe someone else will find this useful some day.
| >
| > There are also R (at least) cpp-using package ndjson and validatejsonr on
| > CRAN.
| >
| > Dirk
| >
| > --
| > http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
| >
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-***@lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Loading...