2

I want to create the following json string

{"water": {"amount": 0}}

To do that I wrote the following code:

  df_water <- list(amount = 0)

  info <- list(water = df_water) %>%
  toJSON()

But that results to:

{"water": {"amount": [0]}}

Any clues how can I remove the array from "amount" value?

Diomides
  • 41
  • 2

1 Answers1

1

Use auto_unbox = TRUE - by default it is FALSE

library(magrittr)
library(jsonlite)
list(water= df_water) %>% 
   toJSON(auto_unbox = TRUE)

-output

{"water":{"amount":0}} 
akrun
  • 874,273
  • 37
  • 540
  • 662