Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

jsonic (Go)

Version: 0.1.15

A Go port of jsonic, the lenient JSON parser. Same architecture, same syntax, same results. If you already use jsonic in TypeScript, you know what this does. If you don't, read on.

jsonic accepts all standard JSON -- and then goes further. Unquoted keys, implicit objects, comments, trailing commas, single-quoted strings, multiline strings, path diving, and more. It parses what you meant, not just what you typed.

Install

go get github.com/jsonicjs/jsonic/go@latest

Quick Example

package main

import (
    "fmt"
    "github.com/jsonicjs/jsonic/go"
)

func main() {
    result, err := jsonic.Parse("a:1, b:2")
    if err != nil {
        panic(err)
    }
    fmt.Println(result) // map[a:1 b:2]
}

That's it. No schema, no struct tags, no ceremony.

Configured Instance

You don't have to accept the defaults. Make gives you a configured parser instance with whatever behavior you need:

func boolp(b bool) *bool { return &b }

j := jsonic.Make(jsonic.Options{
    Number: &jsonic.NumberOptions{Lex: boolp(false)},
})

result, err := j.Parse("a:1, b:2")
// {"a": "1", "b": "2"} — numbers are kept as strings

Options compose. Turn things off, turn things on. You can always change it later.

Syntax

jsonic accepts all standard JSON plus the relaxations listed in the syntax reference. Here are the highlights:

  • Unquoted keys: a:1{"a": 1}
  • Implicit objects: a:1,b:2{"a": 1, "b": 2}
  • Implicit arrays: a,b,c["a", "b", "c"]
  • Comments: #, //, /* */
  • Single/backtick quotes: 'hello', `hello`
  • Path diving: a:b:1{"a": {"b": 1}}
  • Trailing commas: {a:1,}{"a": 1}
  • All number formats: hex, octal, binary, separators

Documentation

License

MIT. Copyright (c) Richard Rodger.