Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library("rjson")
- fromJSON("[{'id': 18, 'name': 'Drama'}, {'id': 28, 'name': 'Action'}, {'id': 10749, 'name': 'Romance'}]")
- js <- '[{
- "id": 14,
- "name": "Fantasy"
- }, {
- "id": 28,
- "name": "Action"
- }, {
- "id": 53,
- "name": "Thriller"
- }]'
- ## this is your invalid string
- js <- "[{'id': 18, 'name': 'Drama'}, {'id': 28, 'name': 'Action'}, {'id': 10749, 'name': 'Romance'}]"
- ## convert it to a valid string
- js <- gsub("QUUX", "'", gsub("'", '"', gsub('"', "QUUX", js)))
- jsonlite::fromJSON(js)
- # id name
- #1 18 Drama
- #2 28 Action
- #3 10749 Romance
- rjson::fromJSON(js)
- [[1]]
- [[1]]$id
- [1] 18
- [[1]]$name
- [1] "Drama"
- [[2]]
- [[2]]$id
- [1] 28
- [[2]]$name
- [1] "Action"
- [[3]]
- [[3]]$id
- [1] 10749
- [[3]]$name
- [1] "Romance"
Add Comment
Please, Sign In to add comment