Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

65
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!