title: Node.js JSON async parsing
body: <p>For example I have this file data.json:</p>
  
  <pre><code>var data = [
    {key: "0:0:0:1", val: 25},
    {key: "0:0:0:2", val: 1},
    {key: "0:0:0:3:0", val: "n/a"},
    {key: "0:0:0:3:1", val: "n/a"},
    {key: "0:0:0:4", val: 0},
    {key: "0:0:0:5", val: 0}
  ];
  </code></pre>
  
  <p>And I have this map.json which I need to use when I parsing data:</p>
  
  <pre><code>{
    "id": "0:0:0:1",
    "type": "0:0:0:2",
    "coords": {
      "latitude": "0:0:0:3:0",
      "longitude": "0:0:0:3:1"
    },
    "unixtime": "0:0:0:4",
    "uptime": "0:0:0:5"
  }
  </code></pre>
  
  <p>And the output I need is:</p>
  
  <pre><code>{"id":25,"type":1,"coords":"latitude":"n/a","longitude":"n/a"},"unixtime":0,"uptime":0}
  </code></pre>
  
  <p>But there's one little problem! I don't know how can I easily parse my data.json async (non-blocking, bla-bla). It's not a JSON in fact and I can't use JSON.parse() method. </p>
  
  <p>Help me please. Tell me how can I make it. How can I parse that data.json?</p>
  
  <p>UPD: Many thanks to dandavis! Now I can parse all files and use it as javascript objects. Now I have another question. In map.json you see "coords" object. How can I make it "coords": { "latitude": "n/a", "longitude": "n/a" } right?
  Now I have this code:</p>
  
  <pre><code>var fs = require('fs');
  
  var map = {};
  var json = {};
  
  var data = function(data, map) {
    fs.readFile(data, function(err, data) {
      if(err) throw err;
  
      var evaluated = eval(data+";data");
  
      evaluated.forEach(function(object) {
  
        fs.readFile(map, function(err, map) {
          if (err) throw err;
  
          map = JSON.parse(map, function(key, value) {
            if(object.key === value) {
              console.log(key + " " + object.val);
              json[key] = object.val;
              return(key + " " + object.val);
            }
          });
  
        console.log(json);
        });
      });
    });
  };
  
  data('data.json', 'map.json');
  </code></pre>
  
  <p>I guess this forEach loop is blocking something. Can I make these loops in another thread or smth? Or maybe there is the suggestion I don't know to make it pretty easy and beautiful code? How can I get JSON in format I need?</p>