Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comment out lines in simple json to put some description

Tags:

json

How do I add comments in a simple JSON file which be read from s3 in AWS. This is my JSON file.

{
    "Parameters": {
        "KeyPairName": "mykey",
        "InstanceTypes": "t2.micro",

        "prodImageIds": "ami-d7abd1b8",
        "testImageIds": "ami-e41b618b",
        "devImageIds": "ami-8f8afde0"
    },
    "StackPolicy": {
        "Statement": [
            {
                "Effect": "Allow",
                "NotAction": "Update:Delete",
                "Principal": "*",
                "Resource": "*"
            }
        ]
    }
}
like image 646
Rehan Ch Avatar asked Aug 31 '17 06:08

Rehan Ch


People also ask

How do I comment a few lines in a JSON file?

No, JSON is a data-only format. Comments in the form //, #, or /* */, which are used in popular programming languages, are not allowed in JSON. You can add comments to JSON as custom JSON elements that will hold your comments, but these elements will still be data.

Can we comment lines in JSON file?

If you're having trouble adding comments to your JSON file, there's a good reason: JSON doesn't support comments.


2 Answers

JSON specification doesn't include comments of any kind. You can simply add a standard key/value pair with a key that gets ignored by the application (maybe _comment) but there is no way to insert a proper comment.

Here the spec details: http://www.json.org/

like image 63
whites11 Avatar answered Oct 03 '22 20:10

whites11


I usually do something like adding "------------------------------------------" : "------------------------------------------" to visually separate "sections".

like image 24
Paco Barter Avatar answered Oct 03 '22 19:10

Paco Barter