Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no method to comment in JSON? [duplicate]

Tags:

json

I was practicing JSON, then suddenly, I came across a communication problem which can only be handled using comment so that I could become able to transfer my logical data structure efficiently to other my programming fellows. I google to search out how to comment in JSON, but the answer that I found was "You can't make comments in JSON". So why did JSON developers not add a method to comment in JSON so other developers can perceive the data correctly? I also posted this same question to code project too, hope I will get the desired answer.

like image 394
Syed Shaharyaar Hussain Avatar asked Apr 16 '15 07:04

Syed Shaharyaar Hussain


1 Answers

JSON stands for Javascript Object Notation. It simply represents a javascript object. There should be no comments since it is meant to be transferred between client and server or client and client, etc. If you need to express a comment in your object you can either use an Enumerated value, or provide documentation on your data output for whatever process you are doing.

If you want to represent that this data is a specific type you can do a shorthand, i.e.:

{
   "type":"server_response",
   "data":{
            ...
          }
}

Although if you are interfacing with someone they should usually provide documentation to what values your methods return.

like image 200
MiltoxBeyond Avatar answered Oct 19 '22 05:10

MiltoxBeyond