How to find out byte size of Objects and Strings in javascript to analyze efficiency of data

I am sending the following data on the server.

        var loc = {
            type            : 'exloc',                      
            ms              : this.var1.move,
            ppx             : this.var1.ppx,
            ppy             : this.var1.ppy,
            Name            : "red",
            rid             : this.gv.GlobalInfoHolder.CurrentRoomID
        };

and I can send this data in the following form also.

 var obj = "type=exloc,ms="+this.var1.move+",ppx="+this.var1.ppx+",ppy="+this.var1.ppy+",Name=red,rid="+this.gv.GlobalInfoHolder.CurrentRoomID;

Then I can strip the data based on the comma's I've put.

Another way would be to encode the object to json then send the data to server and decode.

So I wanted to ask that what will be the best solution for this? It would be better if anyone tells me how to analyze the size in bytes of each of these variables including the json solution also.

I want to go for the solution that gives me the smallest size of the variable.I am doing this for performance and efficiency if anyone wants to suggest something he/she is most welcome.I am considering this because I am working on a real time game which has to share data between client and server very quickly (in milliseconds)

Just get a network analyzer program (like the free Fiddler or many, many other programs available for the same thing) and look to see exactly what is being sent across the wire. I do this all the time to debug client/server problems. It's real easy and shows you exactly what is being sent between client and server.

JSON is not meant to be the most storage efficient format so if you're trying to optimize for size, you can already know that's probably not the best option because formats with less redundancy (single copy of field name vs. many) are nearly always going to be more compact.

In addition, you should first figure out whether any of this matters. If your data is small overall, then the performance difference between 40 bytes and 80 bytes is probably too small to even measure on a single client. On the other hand, if you had thousands of records to transmit, then the size of each record could be enough to make a difference.