-3

This is my data,

 data =  {
        "SeatingArrangement": [{
           "data": [{"id": 1, "rowName": "a", "seatNo": 0},{ "id": 2,"rowName": "a","seatNo": "a1"}],
           "rowName": "a",
        }],
        "TheatreName": "abc natyadalan",
     }

I want to stringify this data and send to API, but in my Fetch.js while stringify this data I'm getting error as,

Unexpected character encountered while parsing value: [. Path 'SeatingArrangement', line 1, position 54.

Shrutika
  • 1
  • 4

3 Answers3

0

Solved this issue.

First I did JSON.stringify on SeatingArrangement object and then the whole data object.

Shrutika
  • 1
  • 4
0

Mistakes:

  • data = at the start of the JSON. You cannot have an = .
  • "rowName": "a", comma after "a".
  • "TheatreName": "abc natyadalan", Again a comma at the end

Fix these and you get a valid JSON. I wish you had gone through JSONLint. You could have seen whether you are having a valid JSON or not.

Sparker0i
  • 1,787
  • 4
  • 35
  • 60
  • data is my variable which I'm passing to my Fetch API and there is no problem with it. – Shrutika Apr 07 '20 at 13:02
  • Actually the json is created dynamically. I can't do anything with trailing comma's. Trying to find solution to remove it. Thanks for your response. @Sparker0i – Shrutika Apr 07 '20 at 13:39
  • When you Stringify that data, you will get error because that is not a valid JSON data... It is not in JSON format at all. JSONs just cannot have = – Sparker0i Apr 07 '20 at 15:30
-1

There is no problem with JSON.stringify. The problem is that you forgot an "before "id".

theMaimu
  • 1
  • 1