Last year I needed a way to be able to parse JSON with comments (also known as JSONC). With that in mind I wrote the following short solution which will essentially remove JavaScript-style comments and trailing commas from the specified JSONC string and then the native JSON.parse() function will parse the remaining string:

Feel free to try this parseJSONC() function out yourself and let me know what you think. As always, happy coding! šŸ˜Ž

Categories: BlogJavaScript

1 Comment

PHP Snippet – parse_jsonc() – Chris West's Blog · June 8, 2022 at 12:00 AM

[…] few months ago I wrote a quick post showing how to parse JSONC (JSON with comments) files in JavaScript. Shortly thereafter I adapted […]

Leave a Reply

Your email address will not be published. Required fields are marked *