Skip to content
/ jsonc Public

Extension of the JSON data format that allows single and multi line comments.

License

Notifications You must be signed in to change notification settings

fpatron/jsonc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonc

Go CI Go Doc

jsonc is an extension of the JSON data format that allows single and multi line comments.

Instalation

To install jsonc, use go get:

 go get github.com/fpatron/jsonc

Features

  • Comment Support: Easily parse JSON files with single-line and multi-line comments.
  • Simple API: Uses a familiar API similar to the standard encoding/json package.

Usage

Here's a basic example of how to use jsonc:

package main

import (
	"fmt"
	"log"
	"os"
	"github.com/fpatron/jsonc"
)

func main() {
	data, err := os.ReadFile("example.json")
	if err != nil {
		log.Fatalf("Failed to read example.json: %v", err)
	}

	var example ExampleData
	err = jsonc.Unmarshal(data, &example)
	if err != nil {
		log.Fatalf("Failed to parse example.json: %v", err)
	}

	fmt.Printf("Parsed data: %+v\n", example)
}

for a complete example checkout this example code

v2 — encoding/json/v2 support

A separate jsonc/v2 module is available for projects that want to use Go's experimental encoding/json/v2 backend. It exposes the same behaviour with the richer v2 Unmarshal(data, v, ...json.Options) signature.

Note: encoding/json/v2 requires Go 1.26 and the GOEXPERIMENT=jsonv2 build flag.

See the v2 README for installation instructions, a full API comparison, and usage examples.

About

Extension of the JSON data format that allows single and multi line comments.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages