go-jsonc provides a way to work with commented json by converting it to plain json.

JSON with comments for GO

  • Decodes a "commented json" to "json". Provided, the input must be a valid jsonc document.
  • Supports io.Reader
  • With this, we can use commented json files as configuration for go applications.

Inspired by muhammadmuzzammil1998

{
	/*
        some block comment
  */
	"string": "foo", // a string
	"bool": false, // a boolean
	"number": 42, // a number
	// "object":{
	//     "key":"val"
	// },
	"array": [
		// example of an array
		1,
		2,
		3
	]
}

Gets converted to (spaces omitted)

{ "string": "foo", "bool": false, "number": 42, "array": [1, 2, 3] }

Motivation

jsonc is great. But this package provides significant performance improvements and simple API to use it with standard library. See benchmarks

Usage

Get this package

go get github.com/akshaybharambe14/go-jsonc

Benchmarks

Here is the performance comparison as compared to JSONC

go-jsonc avoids allocations to heap to gain the performance.

goos: windows
goarch: amd64
pkg: github.com/akshaybharambe14/go-jsonc/benchmarks
BenchmarkOwnSmallJSONBytes-4              256599              4952 ns/op         353.00 MB/s           0 B/op          0 allocs/op
BenchmarkOwnSmallJSONBytesReader-4        206823              5832 ns/op         299.70 MB/s        6224 B/op          5 allocs/op
BenchmarkJSONCSmallJSONBytes-4            171474              6925 ns/op         252.41 MB/s        1792 B/op          1 allocs/op
BenchmarkOwnBigJSONBytes-4                 33517             35921 ns/op         462.26 MB/s           0 B/op          0 allocs/op
BenchmarkOwnBigJSONBytesReader-4          105244             11292 ns/op        1470.45 MB/s        6224 B/op          5 allocs/op
BenchmarkJSONCBigJSONBytes-4               19599             61422 ns/op         270.34 MB/s       18432 B/op          1 allocs/op
PASS
ok      github.com/akshaybharambe14/go-jsonc/benchmarks 26.250s

Example

see examples

License

go-jsonc is open source and available under MIT License

Owner
Akshay Bharambe
Software Developer 👨‍💻️ by passion | Tech Geek | Open for contributions | ❤️ Go | On a mission to spread the knowledge ☑️ | Feel free to get in touch.
Akshay Bharambe
Similar Resources

A simple way to share files and clipboard within a local network.

Shortcut Simple way to share files and clipboard with devices within a local network. Usage Run the ./shortcut executable. A browser window will be op

Mar 13, 2022

Google pub/sub service easy way to use

easy pubsub Installation go get github.com/buraksecer/go-easy-pubsub v0.0.2 Example Firstly, you must Init new topic operation. topic.Init(clientId)

Nov 24, 2022

Our aim is to expand the capabilities of blockchain and make a secure way for transferring NFT between RMRK and MOVR blockchain.

remov Inspiration Our aim is to expand the capabilities of blockchain and make a secure way for transferring NFT between RMRK and MOVR blockchain. The

Jul 25, 2022

HCio is a straightforward way to ping Healthchecks.io checks directly from a Go application

HCio HCio is a straightforward way to ping Healthchecks.io checks directly from a Go application. Getting Started Create a simple Check: check := hcio

Nov 20, 2022

Starting my way through learning Golang by setting up an HTTP server.

Lets-Go Setting up an HTTP server with Golang. Building a simple server with "net/http" library in Golang. This is a simpe server with two routes, the

Aug 22, 2022

The ultimate way to move between folders in the CLI

goto-command The ultimate way to move between folders in the command line Goto is a command that can be used like cd, and also allows you to add speci

Oct 2, 2022

Go-komoot - An easy way to communicate your user with Komoot

Go Komoot library This is an easy way to communicate your user with Komoot. Via

Feb 5, 2022

This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.

This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.

This small Docker project is the easiest way to send notifications directly via .txt files to services like: Gotify, Telegram, SMTP (Email) or Webhook.

Oct 5, 2022

Provides packet processing capabilities for Go

GoPacket This library provides packet decoding capabilities for Go. See godoc for more details. Minimum Go version required is 1.5 except for pcapgo/E

Dec 29, 2022
Comments
  • Add: DecodeBytes ans DecodeString APIs

    Add: DecodeBytes ans DecodeString APIs

    1. Add: DecodeBytes API to convert jsonc byte array.
    2. Add: DecodeBytes API to convert jsonc string.
    3. Add: Tests. 100% Coverage.
    4. Refactor: make decode() reusable.
    5. Update: Readme and examples.
  • Remove dependency

    Remove dependency

    Hi, cool project. Liked the way you can do json.Decoder(jsonc.Decoder(f)).Decode(&s).

    I wish if you could remove depending on github.com/muhammadmuzzammil1998/jsonc in go.mod . As far as I could tell, it's only used in benchmarks/ ?

go HTTP client that makes it plain simple to configure TLS, basic auth, retries on specific errors, keep-alive connections, logging, timeouts etc.

goat Goat, is an HTTP client built on top of a standard Go http package, that is extremely easy to configure; no googling required. The idea is simila

Jun 25, 2022
Share plain text, images and files in Local area network.

LAN-Share Share plain text, images and files in Local area network. Usage $ lan-share -h Usage of lan-share: -addr string Listen on address

Jan 25, 2022
Library to work with eBPF programs from Go

Go eBPF A nice and convenient way to work with eBPF programs / perf events from Go. Requirements Go 1.10+ Linux Kernel 4.15+ Supported eBPF features e

Dec 29, 2022
🍔 Product-storage service, work on gRPC. Client sends the URL to download products, and requests the result.

?? Product-storage service, work on gRPC. Client sends the URL to download products, and requests the result. The server transfer request to a third-party resource for .csv-file uploading and saves the products to own database.

Dec 16, 2021
A simple proxy to work with tcp connection

Proxy It is simple proxy to work with tcp connection HTTP TCP Getting Started pr

Dec 16, 2021
go websocket, a better way to buid your IM server
go websocket, a better way to buid your IM server

Your star is my power!! ?? ⭐ ⭐ ⭐ ⭐ ⭐ Discribe lhttp is a http like protocol using websocket to provide long live, build your IM service quickly scalab

Dec 30, 2022
A new way of working with Protocol Buffers.

Buf All documentation is hosted at https://buf.build. Please head over there for more details. Goal Buf’s long-term goal is to enable schema-driven de

Jan 1, 2023
The fastest way to create self-hosted exit-servers
The fastest way to create self-hosted exit-servers

inletsctl - the fastest way to create self-hosted exit-servers inletsctl automates the task of creating an exit-server (tunnel server) on public cloud

Dec 15, 2022
The easiest, most secure way to use WireGuard and 2FA.

This repository contains all the open source Tailscale client code and the tailscaled daemon and tailscale CLI tool. The tailscaled daemon runs primarily on Linux; it also works to varying degrees on FreeBSD, OpenBSD, Darwin, and Windows.

Jan 8, 2023
It is a proxy to improve article readability, a directory for your favorite articles, and a way to make the internet lighter and more accessible.

timoneiro It is a work in progress. Some features are unimplemented yet. The helmsman's goal is to be a way to browse articles without all the distrac

Jun 13, 2022