jsonlite
jsonlite copied to clipboard
Allow auto_unbox=TRUE when dataframe="column"
auto_unbox=TRUE in toJSON() has been ignored when dataframe="column" since 65680f68; therefore it was not possible to unbox single-row data.frames automatically:
iris1 = head(iris, 1L)
cat(toJSON(iris1, dataframe = "column", auto_unbox = TRUE, pretty = TRUE))
#> {
#> "Sepal.Length": [5.1],
#> "Sepal.Width": [3.5],
#> "Petal.Length": [1.4],
#> "Petal.Width": [0.2],
#> "Species": ["setosa"]
#> }
This PR enables it:
iris1 = head(iris, 1L)
cat(toJSON(iris1, dataframe = "column", auto_unbox = TRUE, pretty = TRUE))
#> {
#> "Sepal.Length": 5.1,
#> "Sepal.Width": 3.5,
#> "Petal.Length": 1.4,
#> "Petal.Width": 0.2,
#> "Species": "setosa"
#> }
Note that it is slightly different from what we get from dataframe="row":
iris1 = head(iris, 1L)
cat(toJSON(iris1, dataframe = "row", pretty = TRUE))
#> [
#> {
#> "Sepal.Length": 5.1,
#> "Sepal.Width": 3.5,
#> "Petal.Length": 1.4,
#> "Petal.Width": 0.2,
#> "Species": "setosa"
#> }
#> ]