title: Parsing JSON in Java without knowing JSON format
body: <p>I am trying to parse JSON strings in Java and find the key-value pairs so that I can determine the approximate structure of the JSON object since object structure of JSON string is unknown.</p>
  
  <p>For example, one execution may have a JSON string like this:</p>
  
  <pre><code>  {"id" : 12345, "days" : [ "Monday", "Wednesday" ], "person" : { "firstName" : "David", "lastName" : "Menoyo" } }
  </code></pre>
  
  <p>And another like this:</p>
  
  <pre><code>  {"url" : "http://someurl.com", "method" : "POST", "isauth" : false }
  </code></pre>
  
  <p>How would I cycle through the various JSON elements and determine the keys and their values? I looked at <code>jackson-core</code>'s <a href="http://fasterxml.github.io/jackson-core/javadoc/2.2.0/com/fasterxml/jackson/core/JsonParser.html" rel="noreferrer"><code>JsonParser</code></a>. I see how I can grab the next "token" and determine what type of token it is (i.e., field name, value, array start, etc), but, I don't know how to grab the actual token's value.</p>
  
  <p>For example:</p>
  
  <pre><code>public void parse(String json)  {
    try {
       JsonFactory f = new JsonFactory();
       JsonParser parser = f.createParser(json);
       JsonToken token = parser.nextToken();
       while (token != null) {
          if (token.equals(JsonToken.START_ARRAY)) {
             logger.debug("Start Array : " + token.toString());
          } else if (token.equals(JsonToken.END_ARRAY)) {
             logger.debug("End Array : " + token.toString());
          } else if (token.equals(JsonToken.START_OBJECT)) {
             logger.debug("Start Object : " + token.toString());
          } else if (token.equals(JsonToken.END_OBJECT)) {
             logger.debug("End Object : " + token.toString());
          } else if (token.equals(JsonToken.FIELD_NAME)) {
             logger.debug("Field Name : " + token.toString());
          } else if (token.equals(JsonToken.VALUE_FALSE)) {
             logger.debug("Value False : " + token.toString());
          } else if (token.equals(JsonToken.VALUE_NULL)) {
             logger.debug("Value Null : " + token.toString());
          } else if (token.equals(JsonToken.VALUE_NUMBER_FLOAT)) {
             logger.debug("Value Number Float : " + token.toString());
          } else if (token.equals(JsonToken.VALUE_NUMBER_INT)) {
            logger.debug("Value Number Int : " + token.toString());
          } else if (token.equals(JsonToken.VALUE_STRING)) {
             logger.debug("Value String : " + token.toString());
          } else if (token.equals(JsonToken.VALUE_TRUE)) {
             logger.debug("Value True : " + token.toString());
          } else {
             logger.debug("Something else : " + token.toString());
          }
          token = parser.nextToken();
       }
    } catch (Exception e) {
       logger.error("", e);
    }
  }
  </code></pre>
  
  <p>Is there a class in <code>jackson</code> or some other library (<code>gson</code> or <code>simple-json</code>) that produces a tree, or allows one to cycle through the json elements and obtain the actual key names in addition to the values?</p>