Uncaught SyntaxError: Unexpected token , in JSON at position 10

rob.m

I am getting a broken json:

Array(1), "40.7197406, 8.563512299999957", "40.7272074, 8.575266499999998", Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1)]
0: ["-22.91401497538739,-68.19866465000001"]
1: ["-25.857842171488155,-54.4140132"]

I tried JSON.parse(data[i].coordinates[i]) but I get that error, the json looks like has some strings but i'm not sure how to fix and make it correct

Barmar

That's not JSON, so don't try to use JSON.parse. Just split it on the commas and call parseFloat().

var data = [{
  coordinates: ["40.7197406, 8.563512299999957", "40.7272074, 8.575266499999998"]
}];

var coords = data[0].coordinates.map(s => s.split(",").map(n => parseFloat(n.trim())));
console.log(coords);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Uncaught SyntaxError: Unexpected token a in JSON at position 2

Uncaught SyntaxError: Unexpected token p in JSON at position 36

Selectize Uncaught SyntaxError: Unexpected token # in JSON at position 0

Uncaught SyntaxError: Unexpected token u in JSON at position 0

React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

how to fix Uncaught SyntaxError: Unexpected token o in JSON at position 1

Facing an Uncaught SyntaxError: Unexpected token o in JSON at position 1

Uncaught SyntaxError: Unexpected token < in JSON at position 0 from Codeigniter response

Uncaught SyntaxError: Unexpected token o in JSON at position 1 error

how to fix "Uncaught SyntaxError: Unexpected token _ in JSON at position . . . "

Uncaught Promise Rejection SyntaxError: Unexpected token u in JSON at position 0

Uncaught SyntaxError: Unexpected token c in JSON at position 13

Uncaught (in promise) SyntaxError: Unexpected token r in JSON at position 0

SyntaxError: Unexpected token \ in JSON at position

SyntaxError: Unexpected token } in JSON at position

JSON object issue: Uncaught SyntaxError: Unexpected token

JSON Parse: Uncaught SyntaxError: Unexpected token e

"Uncaught SyntaxError: Unexpected token H in JSON"

Uncaught SyntaxError: Unexpected token with JSON.parse

Uncaught SyntaxError: Unexpected token - JSON character encoding

javascript json uncaught syntaxerror unexpected token illegal

"Uncaught SyntaxError: Unexpected token" with JSON parse in backbone

Uncaught SyntaxError: Unexpected token U in JSON at position 0 at JSON.parse (<anonymous>) at Response.Body.json

Uncaught SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse (Asp.net MVC)

Uncaught SyntaxError: Unexpected token a in JSON at position 0 at JSON.parse (<anonymous>)

Uncaught SyntaxError: Unexpected token < in JSON at position 0 : at JSON.parse (<anonymous>) at Object.<anonymous>

Jinja Flask issue: Uncaught SyntaxError: Unexpected token { in JSON at position 1 at JSON.parse

Uncaught SyntaxError: Unexpected token d in JSON at position 0 at JSON.parse (<anonymous>)

VM299:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>)