var fs = require('fs');

function jsonObject(fileName) {
  var content = fs.readFileSync(fileName,'utf8');
  return JSON.parse(content);
}

var cfg = jsonObject('../api.json');

function serialize(req,res) {
  if(req.err) {
    res.status(422).json({errors:[{detail:res.err}]});
  }else{
    req.data.forEach(function(data,i) {
      var temp = data[i];
      req.data[i] = {
        _id: temp.id,
        type: 'data',
        attributes:{
        }
      };
      for(field in cfg.rules['/'+req.model].fields){
        data[i].attributes[field] = temp[field];
      }
      
    });
    res.status(200).json({data:JSON.stringify(req.data)});
  }
}

module.exports = serialize;


@@ -1,182 +1,4 @@
-var fs = require('fs');%0A%0Afunction jsonObject(fileName) %7B%0A  var content = fs.readFileSync(fileName,'utf8');%0A  return JSON.parse(content);%0A%7D%0A%0Avar cfg = jsonObject('../api.json');%0A%0A
 func
@@ -83,17 +83,17 @@
 etail:re
-s
+q
 .err%7D%5D%7D)
@@ -298,32 +298,19 @@
  in 
-cfg.rules%5B'/'+req.model%5D
+req.context
 .fie

Update json-serializer.js