title: how to Validate if JSON Path Exists in JSON
body: <p>In a given json document, how to validate if a json path exists ?</p>
  
  <p>I am using <a href="https://github.com/json-path/JsonPath" rel="noreferrer">jayway-jsonpath</a> and have the below code </p>
  
  <pre><code>JsonPath.read(jsonDocument, jsonPath)
  </code></pre>
  
  <p>The above code can potentially throw below exception</p>
  
  <blockquote>
    <p>com.jayway.jsonpath.PathNotFoundException: No results for path:
    $['a.b.c']</p>
  </blockquote>
  
  <p>In order to mitigate it, I intend to validate if the path exists before trying to read it with <strong><em>JsonPath.read</em></strong></p>
  
  <p>For reference I went through the following 2 documentations, but couldn't really get what I want.</p>
  
  <ol>
  <li><a href="http://www.baeldung.com/guide-to-jayway-jsonpath" rel="noreferrer">http://www.baeldung.com/guide-to-jayway-jsonpath</a></li>
  <li><a href="https://github.com/json-path/JsonPath" rel="noreferrer">https://github.com/json-path/JsonPath</a></li>
  </ol>