title: Parsing JSON in javascript coming from Java Jackson JSON
body: <p>I followed this example to generate a json string to be later parsed in javascript</p>
  
  <pre><code>package example;
  
  import org.codehaus.jackson.map.ObjectMapper;
  import java.util.HashMap;
  import java.util.Map;
  
  public class Example {
  
      public static void main(String[] args) {
          Map&lt;String,String&gt; map = new HashMap&lt;&gt;();
          ObjectMapper mapper = new ObjectMapper();
          map.put("key1","value1");
          map.put("key2","value2");
  
          String json = mapper.writeValueAsString(map);
          System.out.println(json);
      }
  }
  </code></pre>
  
  <p>in Javascript:</p>
  
  <pre><code> $http.get('/rest/json-example').
              success(function(data) {
                  //$scope.count = data.length;
                  console.log(data.key1);
                  //console.log(JSON.parse(data));
              }).error(function(error) {
                  console.log(error);
              });
  </code></pre>
  
  <p>I don't know how to parse the string, this is how it gets printed using </p>
  
  <pre><code>console.log(data)
  // Object {key1: "value2", key2: "value1"} 
  </code></pre>
  
  <p>If I use</p>
  
  <pre><code>JSON.parse(data); 
  // I get an error "unexpected SyntaxError: Unexpected token o at Object.parse (native)..."
  </code></pre>
  
  <p>if I try to access it like:</p>
  
  <pre><code>console.log(data[0]);
  // I get undefined
  </code></pre>