2

I have the following code:

data = list(
    "id" = equip_id,
    "initial_date" = 1608433200,
    "final_date" = 1609038000,
    "limit" = 10000,
    "order" = "asc",
    "properties" = "forecast"
)

If I use:

jsonlite::toJSON(data, auto_unbox = TRUE)

I have this:

{"id":3,"initial_date":1608433200,"final_date":1609038000,"limit":10000,"order":"asc","properties":"forecast"} 

But what I want:

{"id":3,"initial_date":1608433200,"final_date":1609038000,"limit":10000,"order":"asc","properties":["forecast"]} 

How can I edit manually which one are arrays or not?

1 Answers1

2

Convert properties to a list:

data = list(
    "id" = equip_id,
    "initial_date" = 1608433200,
    "final_date" = 1609038000,
    "limit" = 10000,
    "order" = "asc",
    "properties" = list("forecast")
)
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225