Skip to content

An implementation of RFC 6901 - JavaScript Object Notation (JSON) Pointer in Golang

License

Notifications You must be signed in to change notification settings

BragdonD/jsonpointer-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonpointer-go

License: MIT Build Status codecov

An implementation of RFC 6901 - JavaScript Object Notation (JSON) Pointer in Golang.

Table of Contents

Introduction

jsonpointer-go is a Go library for working with JSON Pointers as defined in RFC 6901. JSON Pointers provide a way to reference specific parts of a JSON document.

Installation

To install the library, simply run:

go get github.com/bragdond/jsonpointer-go

Usage

Here is a simple example of how to use jsonpointer-go:

package main

import (
    "fmt"
    "github.com/bragdond/jsonpointer-go"
)

func main() {   
	jsonStr := `{
        "foo": ["bar", "baz"],
        "qux": {"corge": "grault"}
    }`

    var jsonData map[string]any
    if err := json.Unmarshal([]byte(jsonStr), &jsonData); err != nil {
        panic(fmt.Sprintf("failed to unmarshal json string: %v", err))
    }

    pointer, err := jsonpointer.Parse("/foo/0")
    if err != nil {
        panic(err)
    }

    result, err := pointer.GetValue(jsonData)
    if err != nil {
        panic(err)
    }

    fmt.Println(result) // Output: bar
}

Contributing

We welcome contributions! Please see the CONTRIBUTING.md file for guidelines on how to contribute.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Happy coding!

About

An implementation of RFC 6901 - JavaScript Object Notation (JSON) Pointer in Golang

Topics

Resources

License

Stars

Watchers

Forks