Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a json with R and controll quotes

I want to create data in R and then export as json. For this I create a list and transform it with jsonlite:: toJSON.
In the json I get all characters in quotes. How can I remove specific quotes.
as.name() and noquote() does not work with jsonlite:: toJason.
Is there a solution to get this done.

Here an example:


x = list(test="false")

x_j=jsonlite::toJSON( x,pretty = T,  auto_unbox = T)
{
  "test": "false"
}

However, the export should look like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


{
  "test": false
}

>Solution :

jsonlite::toJSON will only convert an R logical vector to a json boolean.

In your case, that means you need FALSE, rather than "false", which is an R character vector and gets converted to a json string.

x = list(test=FALSE)

jsonlite::toJSON(x, pretty = T,  auto_unbox = T)

# {
#   "test": false
# }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading