There are a number of packages that have toJSON
and fromJSON
functions.
Using rjson::fromJSON
, '{}'
is read in as a list
of length 0
, whereas RJSONIO::fromJSON
reads in {}
as a named list
of length 0.
In either package, calling fromJSON
on a named list will do what you want.
Clearly, RJSONIO
is performing as you want it to do
RJSONIO::toJSON(RJSONIO::fromJSON('{}'))
## [1] '{}'
rjson::toJSON(rjson::fromJSON('{}'))
## [1] "[]"
If you use rjson
then you will have to manually set the names
of the list of length 0
rjson::toJSON(setNames(rjson::fromJSON('{}'), character(0)))
## [1] "{}"