HuJSON: JSON for Humans (comments and trailing commas)

Related tags

JSON hujson
Overview

HuJSON - Human JSON

The HuJSON decoder is a JSON decoder that also allows

  • comments, both /* ... */ and // to end of line
  • trailing commas on arrays and object members

It is a soft fork of the Go standard library encoding/json package. The plan is to merge in all changes from each Go release.

Currently HuJSON is based on Go 1.13.

Grammar

The changes to the JSON grammar are:

--- grammar.json
+++ grammar.hujson
@@ -1,13 +1,31 @@
 members
 	member
+	member ',' ws
 	member ',' members
 
 elements
 	element
+	element ',' ws
 	element ',' elements
 
+comments
+	"*/"
+	comment comments
+
+comment
+	'0000' . '10FFFF'
+
+linecomments
+	'\n'
+	linecomment
+
+linecomment
+	'0000' . '10FFFF' - '\n'
+
 ws
 	""
+	"/*" comments
+	"//" linecomments
 	'0020' ws
 	'000A' ws
 	'000D' ws
Issues
  • Turn `ObjectMember` into a named type

    Turn `ObjectMember` into a named type

    I'm not sure why ObjectMember is defined as a type alias instead of a named type. In practice, it's probably not a big deal, but it makes autocomplete weird.

    opened by zombiezen 3
  • Initial commit of a HuJSON AST parser and packer

    Initial commit of a HuJSON AST parser and packer

    This package provides a HuJSON parser into an AST represented by the following Go types:

    • Value: A JSON literal, object, or array with surrounding whitespace/comments.
    • ValueTrimmed: A JSON value without surrounding whitespace/comments.
    • Extra: Raw bytes of whitespace and comments.
    • Literal: Raw bytes of a JSON literal (i.e., null, boolean, string, or number).
    • Object: A JSON object.
    • Array: A JSON array.

    The Parse function parses raw HuJSON input as a Value. The Value.Pack method serializes the AST as raw HuJSON output.

    The intention is to delete the fork of "encoding/json" currently here once we migrate all usages to the new code.

    opened by dsnet 3
  • update for go1.14

    update for go1.14

    The base of hujson is go1.13, the specific commit number is in https://github.com/tailscale/hujson/commit/e2a9696a57f84acb1a0b2d50b986b180be9ed8c4. We should git diff go/src/pkg/encoding/json between that commit and go1.14 and apply the diff to hujson.

    opened by crawshaw 3
  • Tests expecting failure accepts success

    Tests expecting failure accepts success

    Some tests that expect a parse error pass even when no such error occurs. For example, the test suite passes after the following change:

    diff --git a/decode_test.go b/decode_test.go
    index 43e9b4a..2d24fcb 100644
    --- a/decode_test.go
    +++ b/decode_test.go
    @@ -457,8 +457,8 @@ var unmarshalTests = []unmarshalTest{
            // syntax errors
            {in: `{"X": "foo", "Y"}`, err: &SyntaxError{"invalid character '}' after object key", 17}},
            {in: `[1, 2, 3+]`, err: &SyntaxError{"invalid character '+' after array element", 9}},
    -       {in: `{"X":12x}`, err: &SyntaxError{"invalid character 'x' after object key:value pair", 8}, useNumber: true},
    -       {in: `[2, 3`, err: &SyntaxError{msg: "unexpected end of JSON input", Offset: 5}},
    +       {in: `{"X":"12x"}`, err: &SyntaxError{"invalid character 'x' after object key:value pair", 8}, useNumber: true},
    +       {in: `[2, 3]`, err: &SyntaxError{msg: "unexpected end of JSON input", Offset: 5}},
    
            // raw value errors
            {in: "\x01 42", err: &SyntaxError{"invalid character '\\x01' looking for beginning of value", 1}},
    
    opened by svenssonaxel 2
  • Add Standardize helper function

    Add Standardize helper function

    This reduces the boilerplate of using hujson with json. We avoid a helper that directly wraps json.Unmarshal since there could be a new json library in the future. Let's avoid a dependency on the json Marshal/Unmarshal semantics and keep this package purely about the HuJSON syntax.

    opened by dsnet 0
  • Delete some deprecated declarations

    Delete some deprecated declarations

    These are not referenced anywhere whether in our own source code or in any publicly available source code.

    The other deprecated declarations will also be deleted once known usages have been cleaned up.

    The hujson package has no compatibility guarantees, so deletion is permissible.

    opened by dsnet 0
  • Fix Unmarshal

    Fix Unmarshal

    The old HuJSON parser had a bug where it couldn't handle trailing comments after the last value. The new parser has no such problem.

    As a quick fix to the deprecated Unmarshal function, use the new parser to strip HuJSON-specific artifacts and then pass the standardized output to Unmarshal.

    opened by dsnet 0
  • Add NewNames and Value.NormalizeNames

    Add NewNames and Value.NormalizeNames

    The NewNames function produces a map of canonical names from a Go struct. It can be passed to Value.NormalizeNames to normalizes case-insensitive matches to a JSON object name to the canonical name.

    opened by dsnet 4
Owner
Tailscale
Tailscale is a WireGuard-based app that makes secure, private networks easy for teams of any scale.
Tailscale
JSON with comments for Go!

JSON with comments for Go! JSONC is a superset of JSON which supports comments. JSON formatted files are readable to humans but the lack of comments d

Muhammad Muzzammil 161 Jun 20, 2022
Package json implements encoding and decoding of JSON as defined in RFC 7159

Package json implements encoding and decoding of JSON as defined in RFC 7159. The mapping between JSON and Go values is described in the documentation for the Marshal and Unmarshal functions

High Performance, Kubernetes Native Object Storage 3 May 10, 2022
Json-go - CLI to convert JSON to go and vice versa

Json To Go Struct CLI Install Go version 1.17 go install github.com/samit22/js

Samit Ghimire 5 Mar 3, 2022
JSON Spanner - A Go package that provides a fast and simple way to filter or transform a json document

JSON SPANNER JSON Spanner is a Go package that provides a fast and simple way to

null 2 May 20, 2022
Get JSON values quickly - JSON parser for Go

get json values quickly GJSON is a Go package that provides a fast and simple way to get values from a json document. It has features such as one line

Josh Baker 10.5k Jun 30, 2022
JSON diff library for Go based on RFC6902 (JSON Patch)

jsondiff jsondiff is a Go package for computing the diff between two JSON documents as a series of RFC6902 (JSON Patch) operations, which is particula

William Poussier 172 Jun 23, 2022
Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Masaaki Goshima 1.6k Jun 26, 2022
Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection

fastjson - fast JSON parser and validator for Go Features Fast. As usual, up to 15x faster than the standard encoding/json. See benchmarks. Parses arb

Aliaksandr Valialkin 1.6k Jun 21, 2022
Fast and flexible JSON encoder for Go

Jettison Jettison is a fast and flexible JSON encoder for the Go programming language, inspired by bet365/jingo, with a richer features set, aiming at

William Poussier 128 Jun 1, 2022
/ˈdʏf/ - diff tool for YAML files, and sometimes JSON

dyff is inspired by the way the old BOSH v1 deployment output reported changes from one version to another by only showing the parts of a YAML file that change.

null 638 Jun 23, 2022
tson is JSON viewer and editor written in Go

tson tson is JSON viewer and editor written in Go. This tool displays JSON as a tree and you can search and edit key or values. Support OS Mac Linux I

skanehira 127 Mar 17, 2022
JSONata in Go Package jsonata is a query and transformation language for JSON

JSONata in Go Package jsonata is a query and transformation language for JSON. It's a Go port of the JavaScript library JSONata.

Blues Inc 25 May 27, 2022
Slow and unreliable JSON parser generator (in progress)

VivaceJSON Fast and reliable JSON parser generator Todo List parse fields parse types generate struct generate (keypath+key) to struct Value Mapping F

null 7 Mar 3, 2022
Kazaam was created with the goal of supporting easy and fast transformations of JSON data with Golang

kazaam Description Kazaam was created with the goal of supporting easy and fast transformations of JSON data with Golang. This functionality provides

Qntfy 205 Sep 17, 2021
Golang JSON decoder supporting case-sensitive, number-preserving, and strict decoding use cases

Golang JSON decoder supporting case-sensitive, number-preserving, and strict decoding use cases

Kubernetes SIGs 12 Apr 3, 2022
Easy JSON parsing, stringifying, and accesing

Easy JSON parsing, stringifying, and accesing

Neutron 1 Nov 23, 2021
json encoding and decoding

jx Package jx implements encoding and decoding of json [RFC 7159]. Lightweight fork of jsoniter. go get github.com/go-faster/jx Usage and examples Roa

go faster 59 Jun 19, 2022
A tool to aggregate and mine data from JSON reports of Go tests.

teststat A tool to aggregate and mine data from JSON reports of Go tests. Why? Mature Go projects often have a lot of tests, and not all of them are i

Viacheslav Poturaev 3 Jan 3, 2022
Search and output the value of JSON by it's path.

Search and output the value of JSON by it's path.

Alexander Dawson 0 Dec 19, 2021