sql >> Base de Datos >  >> NoSQL >> MongoDB

Convertir lista R a JSON

Utilice gsub()

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

Resultados :

  {
    "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"
      }
    ]
  }

Todavía json clase:

> class(jsontest)
[1] "json"

Pero tal vez el espacio en blanco pueda causar algunos problemas.