Converting a received POST request in Node to a Javascript object

I'm sorry for the very basic question but I could not figure this out. This is my first time writing a server. Pretty much we have an iPhone app that consults the server I am writing by doing a POST request with JSON data. When I receive this data, is this equivalent to an object in JavaScript? When I have two objects in Javascript, assuming of the format:

var x = { major_id: 1234, minor_id: 5678};
var y = { major_id: 1234, minor_id: 5678};

Am I able to do:

if (x == y) {
    //do something
}

Or do I need to compare each element in the object individually?

It depends on what you receive from POST. It is most probably stringified JSON, that you can transform into an object using : JSON.parse(receivedString);

Check the type of your variables using typeof x

Once both x and y have the same type, you can compare them as follows :

  • if x AND y are JSON strings, use x==y
  • if they are both objects, you need to compare parameters one by one. Some libraries abstract that for you. For example, you could use Underscore.JS method isEqual and do something like :

    var _ = require('underscore')
    var x = { major_id: 1234, minor_id: 5678};
    var y = { major_id: 1234, minor_id: 5678};
    if(_.isEqual(x, y)){
      //Do stuff
    }