larissacarvalho
larissacarvalho

Reputation: 33

When using jsonlite in R, how to specify manually which are treated as arrays? The auto_unbox doesn't work in this case

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?

Upvotes: 2

Views: 90

Answers (1)

Stéphane Laurent
Stéphane Laurent

Reputation: 84659

Convert properties to a list:

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

Upvotes: 2

Related Questions