Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

over-simplifying #67

Closed
dcooley opened this issue May 24, 2020 · 4 comments
Closed

over-simplifying #67

dcooley opened this issue May 24, 2020 · 4 comments

Comments

@dcooley
Copy link
Collaborator

dcooley commented May 24, 2020

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
Copy link
Contributor

knapply commented May 24, 2020

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 added a commit that referenced this issue May 24, 2020
@dcooley
Copy link
Collaborator Author

dcooley commented May 24, 2020

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
Copy link
Collaborator Author

dcooley commented May 24, 2020

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

dcooley added a commit that referenced this issue May 25, 2020
@dcooley
Copy link
Collaborator Author

dcooley commented May 25, 2020

Notes for me to remember in the morning:

  • commit c920159 has a potential soultion
  • if it works (all tests currently pass), I can remove my sequential_array_counter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants