MongoDB
 sql >> Datenbank >  >> NoSQL >> MongoDB

Konvertieren der R-Liste in JSON

Verwenden Sie gsub()

jsontest <- gsub(pattern = '^\[', replacement = "", x = jsontest)
jsontest <- gsub(pattern = '\]$', replacement = "", x = jsontest)

Ergebnisse :

  {
    "section_id": {},
    "name": "name1",
    "slug": "slug1"
  },
  {
    "section_id": {},
    "name": "name2",
    "slug": "slug2"
  },
  {
    "section_id": {},
    "name": "name3",
    "slug": "slug3",
    "categories": [
      {
        "section_id": {},
        "name": "name31",
        "slug": "slug31"
      },
      {
        "section_id": {},
        "name": "name32",
        "slug": "slug32"
      }
    ]
  }

Immer noch json Klasse :

> class(jsontest)
[1] "json"

Aber vielleicht verursacht das Leerzeichen Probleme.