2

I was trying to use jsonlite to work with my JSON requests. I was expecting that applying toJSON() to the result of fromJSON() and writing it to a file will produce the same JSON as the original. Apparently, fromJSON does a lot of type conversion from numeric to character and encloses single values into [].

Are there any parameters I can use to make sure we obtain the same json file by toJSON(fromJSON) or I have to care about all the types of all elements myself.

Maybe this could be achieved by some other R JSON library.

Here is the sample of original JSON and past transformation.

Original:

"target": "LENGTH",
"solvers_list": "TMtmil",   "passes_num": 45

Modified:

"target":["LENGTH"],"solvers_list":["TMtmil"],"passes_num":[45]
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205

1 Answers1

2

You may need to post the actual JSON (your "Original" is not JSON) if this doesn't help:

orig <- '{"target":"LENGTH","solvers_list":"TMtmil","passes_num":45}'

orig == jsonlite::toJSON(jsonlite::fromJSON(orig), auto_unbox=TRUE)
## [1] TRUE
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205