title: Parsing JSON using php jsonpath
body: <p>I'm trying to parse a JSON in PHP using jsonpath .... </p>
  
  <p>My JSON is coming from this </p>
  
  <p><a href="https://servizionline.sanita.fvg.it/tempiAttesaService/tempiAttesaPs" rel="noreferrer">https://servizionline.sanita.fvg.it/tempiAttesaService/tempiAttesaPs</a></p>
  
  <p>(it's quite too long to cut/paste here but you can see it in a browser session ....)</p>
  
  <p>The JSON is a valid JSON (I've verified it using <a href="https://jsonlint.com/" rel="noreferrer">https://jsonlint.com/</a> ... ).</p>
  
  <p>I've tried the jsonpath expression using <a href="http://www.jsonquerytool.com/" rel="noreferrer">http://www.jsonquerytool.com/</a> and all seems works fine, but when I put all in my PHP code sample below .... </p>
  
  <pre><code>&lt;?php  
      ini_set('display_errors', 'On');
      error_reporting(E_ALL);
  
      require_once('json.php');      // JSON parser
      require_once('jsonpath-0.8.0.php');  // JSONPath evaluator
  
      $url = 'https://servizionline.sanita.fvg.it/tempiAttesaService/tempiAttesaPs';
  
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
      curl_setopt($ch, CURLOPT_PROXY, '');
      $data = curl_exec($ch);
      curl_close($ch);
  
      $parser = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
      $o = $parser-&gt;decode($data);
  
      $xpath_for_parsing = '$..aziende[?(@.descrizione=="A.S.U.I. - Trieste")]..prontoSoccorsi[?(@.descrizione=="Pronto Soccorso e Terapia Urgenza Trieste")]..dipartimenti[?(@.descrizione=="Pronto Soccorso Maggiore")]..codiciColore[?(@.descrizione=="Bianco")]..situazionePazienti..numeroPazientiInAttesa';
  
      $match1 = jsonPath($o, $xpath_for_parsing);
      //print_r($match1);
      $match1_encoded = $parser-&gt;encode($match1);
      print_r($match1_encoded);
  
      $match1_decoded = json_decode($match1_encoded);
  
      //print_r($match1_decoded);
  
      if ($match1_decoded[0] != '') {
       return  $match1_decoded[0];
      }
      else {
       return  "N.D.";
     } 
  ?&gt;
  </code></pre>
  
  <p>... no values are printed .. only a "false" value. </p>
  
  <p>Something goes wrong in my jsonpath expression when I put it in my PHP code: ths error that coming out is the follow</p>
  
  <pre><code>Warning: Missing argument 3 for JsonPath::evalx(), called in /var/www/html/OpenProntoSoccorso/Test/jsonpath-0.8.0.php on line 84 and defined in /var/www/html/OpenProntoSoccorso/Test/jsonpath-0.8.0.php on line 101
  
  Notice: Use of undefined constant descrizione - assumed 'descrizione' in /var/www/html/OpenProntoSoccorso/Test/jsonpath-0.8.0.php(104) : eval()'d code on line 1
  </code></pre>
  
  <p>Probably I've to escape / quoting my jsonpath to use it in PHP but I don't know how ... any suggestion is appreciated ... </p>
  
  <p>NOTE: I need to use jsonpath expressions like <code>?(@.descrizione=="A.S.U.I. - Trieste")</code> and I can't use "positional" json path ...</p>
  
  <p>I've also tried to use jsonpath-0.8.3.php coming from here <a href="https://github.com/ITS-UofIowa/jsonpath/blob/master/jsonpath.php" rel="noreferrer">https://github.com/ITS-UofIowa/jsonpath/blob/master/jsonpath.php</a>, but nothing  change ... </p>
  
  <p>Suggestions? </p>
  
  <p>Thank you in advance ... </p>