简体   繁体   中英

How do I wrap JSON with square brackets in R language?

I have a nested JSON as follows and I would like to wrap it with square brackets and return it. How could I achieve it in R with ease? Input:

"{
    "info": {
        "val": 0.1885,
        "id": 1
    }
}, {
    "info": {
        "val": 1.3599,
        "id": 2
    }
}"

Output:

[{
    "info": {
        "val": 0.1885,
        "id": 1
    }
}, {
    "info": {
        "val": 1.3599,
        "id": 2
    }
}]

Thank you

Not sure if you found the solution for this, but the following should work:

wrap_json <- function(x) {
  return(paste0("[", x, "]"))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM