title: How to get value by key on any level of json document?
body: <p>I write method which parses string. I know that string has a json format.</p>
  
  <p>Also I know that it contains values for <code>lat</code> and <code>lng</code> but It can be on any level.</p>
  
  <p>I wrote following code to implement getting value by key:</p>
  
  <pre><code>Map jsonBodyMap = objectMapper.convertValue(body, Map.class);
  String lat = getByKey(jsonBodyMap, "lat");
  
  
  
  private String getByKey(Map&lt;?, ?&gt; map, String key) {
      Object value = map.get(key);
      if (value != null) {
          return String.valueOf(value);
      }
      for (Map.Entry entry : map.entrySet()) {
          Object entryValue = entry.getValue();
          if (entryValue instanceof Map) {
              String val = getByKey((Map) entryValue, key);
             if (val != null) {
                  return val;
              }
          }
      }
      return null;
  }
  </code></pre>
  
  <p>But it doesn't look like a nice solution.</p>
  
  <p>Do you know a better way to implement it?</p>