Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

67
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda