over-simplifying
dcooley opened this issue · 4 comments
dcooley commented
I'm simplifying one-step too much in this exmaple
test <- '{"test":[1,[2,[3]]]}'
jsonlite::fromJSON(test)
#> $test
#> $test[[1]]
#> [1] 1
#>
#> $test[[2]]
#> $test[[2]][[1]]
#> [1] 2
#>
#> $test[[2]][[2]]
#> [1] 3
jsonify::from_json(test)
#> $test
#> $test[[1]]
#> [1] 1
#>
#> $test[[2]]
#> [,1]
#> [1,] 2
#> [2,] 3
smaller example for testing
from_json('[1,[2]]')
knapply commented
Follow-up on eddelbuettel/rcppsimdjson#10 (comment)
Is the following what's desired?
test1 <- jsonify::from_json(
'{
"a": [
1,
[
2,
[
3
]
]
]
}', simplify = FALSE
) # except w/ the default `simplify = TRUE`
target1 <- list(
a = list(
1L,
list(
2L,
list(
3L
)
)
)
)
stopifnot(identical(test1, target1))
test2 <- jsonify::from_json(
'{
"a": [
1,
[
2,
[
3,
4
]
]
]
}'
)
target2 <- list(
a = list(
1L,
list(
2L,
c(3L,
4L)
)
)
)
stopifnot(identical(test2, target2))
dcooley commented
Yes.
But, now you've brought it up, I'm having a slight crisis-of-confidence on how the "simplifying" is working vs what I intended it to do back when it was written...
dcooley commented
This is seemingly a one-off edge case that needs handling, rather than something systemic
## incorrect
from_json( '[1,[2]]' )
# [,1]
# [1,] 1
# [2,] 2
Given these exmples are correct
## right
from_json( '[[1,2],2]' )
# [[1]]
# [1] 1 2
#
# [[2]]
# [1] 2
from_json( '[5,[6,7]]' )
# [[1]]
# [1] 5
#
# [[2]]
# [1] 6 7