Home >Web Front-end >JS Tutorial >How to add comments to json files?

How to add comments to json files?

青灯夜游
青灯夜游Original
2019-05-31 17:09:0416331browse

How to add comments to json files?

Adding comments // or /**/ is not allowed in JSON files

JSON has two data structures:

● Name /A collection of value pairs: key: value style;

● An ordered list of values: Array;

The JSON document states that as long as it does not conform to the above two structures, Not supported and an error message is displayed.

So how can we add comments to JSON?

If you really need to use comments in the .json file, you can use the following two methods:

1. Use key: value to add

You can use key: value adds a data element to the JSON that acts as an annotation.

How to add comments to json files?

If necessary, tell the client using this JSON data in the JSON data description document: ignore the "comment" data element when parsing the data.

2. Use JSON.minify() function;

By using JSON.minify(test.json), you can delete comments and spaces in the test.json file, so that the comments with comments .json file is compiled

The above is the detailed content of How to add comments to json files?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn