Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 2.74 KB

README.md

File metadata and controls

78 lines (60 loc) · 2.74 KB

jsonptr - JSON Pointer (RFC 6901) for Go

GoDoc codecov Go Report Card

Features

Goals:

  1. First-class interface
  2. Correctness (most existing open source Go implementations have limitations in their interface or have implementation bugs)
    • Full testsuite (work in progress)
    • Reject invalid escapes (regexp /~[^01]/)
    • Allow any JSON value as leaf node
    • Allow any JSON value as root (not just a map[string]interface{})
    • Allow to get/set the root of the document with the empty pointer ""
  3. Speed (see benchmark)
    • No reflect
    • Optimised parsing

Example

package main

import (
    "fmt"
    "github.com/dolmen-go/jsonptr"
)

func main() {
    // JSON: { "a": [ 1 ] }
    document := map[string]interface{}{
        "a": []interface{}{
            1,
        },
    }

    val, err := jsonptr.Get(document, `/a/0`)
    if err != nil {
        fmt.Printf("Error: %s\n", err)
    } else {
        fmt.Printf("Got: %v\n", val)
    }
}

Status

Production ready.

The aim is code coverage of 100%. Use go coverage tools and consider any code not covered by the testsuite as never tested and full of bugs.

Todo:

  • tests of error cases

License

Copyright 2016-2020 Olivier Mengué

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.