Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/getify/JSON.minify
Simple minifier for JSON to remove comments and whitespace
https://github.com/getify/JSON.minify
Last synced: 7 days ago
JSON representation
Simple minifier for JSON to remove comments and whitespace
- Host: GitHub
- URL: https://github.com/getify/JSON.minify
- Owner: getify
- Created: 2010-06-22T12:25:20.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2024-02-06T01:56:05.000Z (9 months ago)
- Last Synced: 2024-07-25T11:22:08.802Z (4 months ago)
- Homepage: http://web.archive.org/web/20100629021329/http://blog.getify.com/2010/06/json-comments/
- Size: 109 KB
- Stars: 408
- Watchers: 25
- Forks: 102
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON minify
Minify blocks of JSON-like content into valid JSON by removing all white-space *and* C/C++ style comments.
JSON parsers (like JavaScript's `JSON.parse()` parser) generally don't consider JSON with comments to be valid and parseable. So, the intended usage is of this project is to minify development-friendly JSON (i.e with comments) to valid JSON before parsing, such as:
```js
JSON.parse(JSON.minify(str))
```Now you can maintain development-friendly JSON documents, where your source is formatted & commented, but minify them before parsing or before transmitting them over-the-wire.
As transmitting bloated (ie, with comments/white-space) JSON would be wasteful and silly, this JSON minify can also be used for server-side processing environments where you can strip comments/white-space from JSON before parsing a JSON document or before transmitting such over-the-wire from server to browser.
Though comments are not officially part of the JSON standard, [this][yahoo-groups-link] post from Douglas Crockford back in late 2005 helps explain the motivation behind this project.
> A JSON encoder MUST NOT output comments. A JSON decoder MAY accept and ignore comments.
Basically, comments are not in the JSON *generation* standard, but that doesn't mean that a parser can't be taught to ignore them. Which is exactly what JSON minify is for.
The first implementation of JSON minify was in JavaScript (as `JSON.minify`), but the intent is to port the implementation to as many other environments and languages as possible/practical.
## Using JSON Minify
Currently, JSON minify has been ported to multiple languages including PHP, Python, Objective C. Each of these ports live on a separate branch in the [Github repository][repo-link]. Language specific instructions can be found in their respective branches.[yahoo-groups-link]: http://web.archive.org/web/20130101004216/http://tech.groups.yahoo.com/group/json/message/152
[php-port]: https://github.com/getify/JSON.minify/tree/php
[repo-link]: https://github.com/getify/JSON.minify