title: Get all the keys in a JSON string JsonNode in java
body: <p>I have a json string which I need to validate and find any other keys other than in a list is there in the json string. The sample json string is</p>
  <pre><code>{
      &quot;required&quot; : true,
      &quot;requiredMsg&quot; : &quot;Title needed&quot;,
      &quot;choices&quot; : [ &quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot; ],
      &quot;choiceSettings&quot; : {
          &quot;a&quot; : {
              &quot;exc&quot; : true
          },
          &quot;b&quot; : { },
          &quot;c&quot; : { },
          &quot;d&quot; : {
              &quot;textbox&quot; : {
                  &quot;required&quot; : true
              }
          }
      },
      &quot;Settings&quot; : {
          &quot;type&quot; : &quot;none&quot;
      }
  }
  </code></pre>
  <p>To allow only predifined keys is exsist in the json string I want to get all the keys in the json string. How can I obtain all the keys in the json string. I am using jsonNode. My code till now is</p>
  <pre><code>        JsonNode rootNode = mapper.readTree(option);
          JsonNode reqiredMessage = rootNode.path(&quot;reqiredMessage&quot;);             
          System.out.println(&quot;msg   : &quot;+  reqiredMessage.asText());            
          JsonNode drNode = rootNode.path(&quot;choices&quot;);
          Iterator&lt;JsonNode&gt; itr = drNode.iterator();
          System.out.println(&quot;\nchoices:&quot;);
          while (itr.hasNext()) {
              JsonNode temp = itr.next();
              System.out.println(temp.asText());
          }    
  </code></pre>
  <p>How to get all the keys from the json string using <code>JsonNode</code></p>