0

I got 2 JSON files extracted from the same db,

a:)

{
    "hint_data": {
        "locations": ["AXQDAP____8AAAAABwAAABEAAAAYAAAAIwIAAERwAgAAAAAADgyCAef7TAMCAAEB", "bOsDAP____8AAAAAAwAAAAcAAADFAQAAFAAAAEJwAgAAAAAANQeCAdzdTAMFAAEB"],
        "checksum": 326195011
    },
    "route_name": ["", ""],
    "via_indices": [0, 15],
    "via_points": [
        [25.299982, 55.376873],
        [25.29874, 55.369179]
    ],
    "found_alternative": false,
    "route_summary": {
        "end_point": "",
        "start_point": "",
        "total_time": 101,
        "total_distance": 871
    },
    "route_geometry": "{_ego@m}|rhBpBaBvHuC`EuArEUtEtAlDvEnD`MlDvMli@hsEfFzn@QlTgNhwCs@fKwBjF",
    "status_message": "Found route between points",
    "status": 0
}

b:)

{
    "alternative_names": [
        ["", ""]
    ],
    "route_name": ["", ""],
    "status_message": "Found route between points",
    "route_geometry": "qo{o@wpslhBmFZwEpBgDzDeBlFWdGv@GCzEyBfIyEtEoNtEuMpAuHkAsCgC[mB{AgCuA{@uCa@}Cl@yBtB}@lDVhEcAtDmCdBcDx@iDDeDk@uBeBeB_CcGcXyFi^{Dg\\wBkP_Fs^wBiS_Ce[_D}UwAcKiBqIgI_TeLaUcMmP_IsHqf@_WyJeE}FMkDjIiTth@y|@loBq^vy@mu@fw@cUxOco@r^gb@zRoOjPsBfMq@rMjBdPnEpKlEnHJ~Dvn@la@nd@pT|f@lLv_@pRzLbHnb@fUxc@lMnaC~zAncBxnAkB|bB|CbmCl]rYxCzkCjwBzoBjxGl_G|fNhcMf~E~mE~pFt}EjbBlzAhvInyHfqDb~CblAw@poAzt@z}@bb@diD~dBxtEjgCfjDljBpuAfw@bpGngDhqF~yC~g@la@v~@ni@rbAjg@jPJlCFNdDGdDu@j@eAhBa@lCLdCaCjI_BtCy@vA_DvF}qAf}Bof@l{@{CnFoKdR}mAxBgM|TkJxPmLlSsf@|}@gf@x@kOzXmEfGmSx^kf@tw@mDtL}k@r~@ykCjjEau@niAee@bu@uUl\\}DpFzCrCr|@dt@|NbLroBx_BdZlV|DbDpBr~Anq@xm@r|@ls@|y@dq@}OXuMQcDhEoBgBeCCu[xXmBH",
    "route_summary": {
        "end_point": "",
        "start_point": "",
        "total_time": 824,
        "total_distance": 15391
    },
    "found_alternative": true,
    "alternative_summaries": [{
        "end_point": "",
        "start_point": "",
        "total_time": 886,
        "total_distance": 14967
    }],
    "via_points": [
        [25.196808, 55.273754],
        [25.139168, 55.187702]
    ],
    "status": 0,
    "via_indices": [0, 144],
    "hint_data": {
        "locations": ["TdMLAP____8AAAAADwAAAA8AAAA9AAAAbAAAAOtwBgAAAAAACXmAARxpSwMEAAEB", "4Q4AAGKyBgAAAAAACQAAAAAAAAAhAQAAAAAAAGUYAAAAAAAA4Zd_AfgYSgMGAAEB"],
        "checksum": 326195011
    },
    "alternative_geometries": ["qo{o@wpslhBmFZwEpBgDzDeBlFWdGv@GCzEyBfIyEtEoNtEuMpAuHkAsCgC[mB{AgCuA{@uCa@}Cl@yBtB}@lDVhEcAtDmCdBcDx@iDDeDk@uBeBeB_CcGcXyFi^{Dg\\wBkP_Fs^wBiS_Ce[_D}UwAcKiBqIgI_TeLaUcMmP_IsHqf@_WyJeE}FMkDjIiTth@y|@loBq^vy@ec@vfAyeAfcCok@vtA}Wtx@uS|d@skAvfCgExJgJpTqH|O}@n~@wSve@qEhKkYdp@gB~DuUrk@_JdRsAhDmJlVqd@rcAuM|Zeg@zkAiKzUgIbS}B~EtDvBhr@a@dQ~J|rBpmAj_CfyAlAzD^lDgHnOyQlg@w[l|@}Q~d@eBB}Af@mAdAw@bBWpBJrBn@hBaAjGif@ptAk^rmAoVxy@cHjPmCHE|Bp[xRpc@ZfLvIzLlIreG~cEjrArz@rmAl|@lbDrzBjWlQ|xA~bAho@pc@d_@jWng@j^hNzJvGnEnPjLlAx@lgAhv@bGvCjkBvoAbjDr}BvfAx{@t\\rSfoDviC~zAjgAfOxIvAbAjwCtsBv|@|m@bD|BvLId_Dt|BtLlIxsAx_AfE~Crn@hc@rKvIh_BniApe@z\xIpGtoBpxAtEdDrQrMzjChlB~@lo@nwFpE|jBl|AzFzE|DfDvDrCjKfJr@n\\pLzKnBzzAdO~LhaFxaEzCdCnLpKbp@ti@nIjHdRzMjo@tg@~MvKpwCtdClw@bm@z[bWfr@vk@zCrCr|@dt@|NbLroBx_BdZlV|DbDpBr~Anq@xm@r|@ls@|y@dq@}OXuM`QcDhEoBgBeCCu[xXmBH"],
    "alternative_indices": [0, 183]
}

And I am running this script on every JSON file. Here is the script.

<?php
    $json       = '{"hint_data":{"locations":["AXQDAP____8AAAAABwAAABEAAAAYAAAAIwIAAERwAgAAAAAADgyCAef7TAMCAAEB","bOsDAP____8AAAAAAwAAAAcAAADFAQAAFAAAAEJwAgAAAAAANQeCAdzdTAMFAAEB"],"checksum":326195011},"route_name":["",""],"via_indices":[0,15],"via_points":[[25.299982,55.376873],[25.29874,55.369179]],"found_alternative":false,"route_summary":{"end_point":"","start_point":"","total_time":101,"total_distance":871},"route_geometry":"{_ego@m}|rhBpBaBvHuC`EuArEUtEtAlDvEnD`MlDvMli@hsEfFzn@QlTgNhwCs@fKwBjF","status_message":"Found route between points","status":0}';
    $data       = json_decode($json);
    $totalTime  = $data->route_summary->total_time;
    var_dump($totalTime);    // DUMPS     101

I am getting the first JSON file output correctly but I am getting an error in the 2nd one.

Please tell me what's wrong with the JSON file.

2
  • What*s the error you get? Commented May 26, 2016 at 8:28
  • First of all "I am getting an error" is useless to anyone trying to help you. Always include the actual error text in your question. Your problem is that the "alternative_geometries" string is not properly escaped, it contains a single \ before an x making it read as \x which is not a valid special character. Commented May 26, 2016 at 8:32

2 Answers 2

4

Your json is not valid.

The "alternative_geometries" property contains a string that is not properly encoded. (\x is not valid. If you want the slash, then it would need to be \\x)

Try validating it somewhere like this: http://jsonlint.com/

Sign up to request clarification or add additional context in comments.

Comments

0

1) put data to text file

2) try again with:

<?php

$data = file_get_contents('./relative/path/to/file.json');
$data = json_decode($data);
$totalTime  = $data->route_summary->total_time;
var_dump($totalTime);
  • it would be better to write data to files and put somewhere to download them to check the file.

2 Comments

How this solution can work for you? when there is a problem with JSON data as pointed by @rik-heywood ?
@itzmukeshy7 because in question he just copy paste data to variable, and there maybe some symbols that are not parsed as usual. So it's better to keep it as-is in file and read it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.