Unexpected token in JSON at position

The Open Data Toll Calculator API v2 toll_calc/match returns error

> { "error": "Unexpected token J in JSON at position 397" }

The request JSON is as follows:

> {
>   "polyline": "zeymE_xny[zHaG`CzCTBmAfBW`@Yf@_AzBi@lAWz@K^GR@`@?h@BLNb@H`@@PPXTb@^~@pBtE`A~BdApC|BtG|CrJ`@vAt@fCVdAr@jCH~@D~AEbCEn@lB^rAV?A?A@ADCFB@F|BH?CBCDAFF`GV|`@tAnGRR@TFz@p@|DrBfGvCBCFADBBHA@|PnIrB~@N@b@J@GRCN@fNdBN@FALIPXPZ`DnF`C`ExBrDx@fBd@|@lB~CdAfBTv@R|@JvANtBJh@X|@h@fBz@nC|AdFnCdJpE`OnA|DpAfEbD{A`D{ApCuArDgBnAfEtAxE^Op@[rCsAxG{CZQdAUjC_@dO_CrSmCxEs@zBY~CWn@Eh@Mf@UrAaA|DmC`BmALONVP\J\Lj@NjBBvBA~AAbDZjIHrA\bD|@pEbB`IzBlGxAfEHXH`@HZf@xAn@~Bt@`Ed@xDfA`LNtCVbFNdGCvGg@zLOxBAnBLpEPfD\`C^lBJf@LBDFx@fC|@zC~BzFl@vAfAfDx@nC~@rDR~@HRXjAT`@JFXFpC{@\Kl@Qd@O~By@dGwBbAc@ZQ`Am@z@w@n@w@b@m@z@{@hA_AnEqDjDmC",
>   "vehicleClass": "A",
>   "vehicleClassByMotorway": {
>     "LCT": "A",
>     "CCT": "A",
>     "ED": "A",
>     "M2": "A",
>     "M5": "A",
>     "M7": "A",
>     "SHB": "A",
>     "SHT": "A",
>     "M4": "A"
>   },
>   "excludeToll": true,
>   "includeSteps": false,
>   "departureTime": "2021-05-26T03:12:42.327Z"
> }

Is the issue with the polyline ? The polyline plot is accurate as required.

Hi @shakyavi

You need to encode (escape) your polyline into a JSON string as it’s got special characters in there which need to be encoded.

If you’re doing this programmatically, most languages have built-in libraries to handle JSON encoding. e.g. JSON.stringify() for JS or json_encode() for PHP.

If you’re just doing this as a test, you can try something like this: Free Online JSON Escape / Unescape Tool - FreeFormatter.com

© Transport for NSW