Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

66
Vistas
Recursive JSON tree does not work when parsed

So I am making a file tree list structure in the front end and it produces a JSON tree. Every time I modify the tree I post the object to the backend in order to store the new leafs that I add. Here is the tree structure that I am passing to the backend

{
    "0": {
        "id": "1",
        "isLeaf": true,
        "_id": "626584371ff07c474d6da2b3",
        "pid": 0,
        "isRoot": true,
        "isActive": true,
        "type": "testSite2",
        "name": "testSite2",
        "ownerUid": "XeqTkJ5VUnWFYWK7bKWXeQ58yLF3",
        "createdAt": "2022-04-24T17:09:11.877Z",
        "updatedAt": "2022-04-24T17:09:11.877Z",
        "__v": 0
    },
    "1": {
        "id": "3",
        "isLeaf": false,
        "_id": "626584a31ff07c474d6da2f3",
        "pid": 0,
        "isRoot": true,
        "isActive": true,
        "type": "testSite2",
        "name": "todelete",
        "ownerUid": "XeqTkJ5VUnWFYWK7bKWXeQ58yLF3",
        "createdAt": "2022-04-24T17:10:59.897Z",
        "updatedAt": "2022-04-24T17:10:59.897Z",
        "__v": 0,
        "children": [
            {
                "isLeaf": true,
                "name": "test",
                "ownerUiD": "XeqTkJ5VUnWFYWK7bKWXeQ58yLF3",
                "type": "testType",
                "id": 1650988619073,
                "isRoot": "false",
                "isActive": "true",
                "pid": "3"
            }
        ]
    }
}

When I send this as is to the backend it returns an error 400 so I try to resolve by parsing it before I pass, whenever I do JSON.parse() on the structure it returns this error:

SyntaxError: Unexpected token o in JSON at position 1

I tried verifying my JSON structure and it passes as a valid JSON, I tried to stringify it and it returns the same error. What am I missing here?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The reason has to be because the method expects a string and you have returned a object to it ,thats when this error occurs.Do check your code for any conversions from object to string in previous lines.If what you require is for the data to be sent as a object instead of a string,you can send it without parsing it.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda