SyntaxError: Unexpected Number (JSON.parse)
javascript, json, parsing
Solution
You can start by simplifying this down to where the problem occurs, in `bc_list`...
JSON.parse('{"bc_list": ["", "{\"257\":\"14\"}]"]}')
The issue is that your backslashes are being considered for the outer quotes on `JSON.parse()` instead of the inner data. You must escape the backslashes as well.
JSON.parse('{"bc_list": ["", "{\\"257\\":\\"14\\"}]"]}')
Your whole line fixed becomes:
JSON.parse('{"start_date_time": ["2012-12-05 04:45:42.135000", "None"], "terminal_no": ["T1081", "None"], "master_doc_no": ["100008", "100008"], "notes": ["", ""], "doc_no": ["1000018", "1000019"], "location_code": ["1005", "1005"], "end_date_time": ["2012-12-05 05:27:04.529000", "None"], "doc_status": ["CC Ended", "Draft"], "bc_list": ["[{\\"465\\":\\"85\\"},{\\"306\\":\\"6\\"},{\\"306\\":\\"47\\"},{\\"306\\":\\"366\\"},{\\"306\\":\\"634\\"}]", "[{\\"257\\":\\"14\\"}]"]}')
Don't use JSON data within strings within JSON data. It's a mess.
Problem
My JSON string, ``` JSON.parse('{"start_date_time": ["2012-12-05 04:45:42.135000", "None"], "terminal_no": ["T1081", "None"], "master_doc_no": ["100008", "100008"], "notes": ["", ""], "doc_no": ["1000018", "1000019"], "location_code": ["1005", "1005"], "end_date_time": ["2012-12-05 05:27:04.529000", "None"], "doc_status": ["CC Ended", "Draft"], "bc_list": ["[{\"465\":\"85\"},{\"306\":\"6\"},{\"306\":\"47\"},{\"306\":\"366\"},{\"306\":\"634\"}]", "[{\"257\":\"14\"}]"]}') ``` But its throwing SyntaxError: Unexpected Number Where am i wrong over here?