gojsonexplode

package
v0.0.0-...-485d38d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2017 License: MIT, Apache-2.0 Imports: 3 Imported by: 0

README

gojsonexplode

What is gojsonexplode?

gojsonexplode go library to flatten/explode nested JSON.

How does it work?

import (
    "fmt"

    "github.com/nytlabs/gojsonexplode"
)
func main() {
    input := `{"person":{"name":"Joe", "address":{"street":"123 Main St."}}}`
    out, err := gojsonexplode.Explodejsonstr(input, ".")
    if err != nil {
        // handle error
    }   
    fmt.println(out))
}

should print:

{"person.address.street":"123 Main St.","person.name":"Joe"}
How are JSON arrays handled?

JSON arrays are flattned using the parent attribute concatenated with a delimiter and the respective index for each of the elements in the array

{"list":[true, false]}

gets exploded to:

{"list.0": true, "list.1":false}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Explodejson

func Explodejson(b []byte, d string) ([]byte, error)

Explodejson takes in a nested JSON as a byte array and a delimiter and returns an exploded/flattened json byte array

func Explodejsonstr

func Explodejsonstr(s string, d string) (string, error)

Explodejsonstr explodes a nested JSON string to an unnested one parameters to pass to the function are * s: the JSON string * d: the delimiter to use when unnesting the JSON object. {"person":{"name":"Joe", "address":{"street":"123 Main St."}}} explodes to: {"person.name":"Joe", "person.address.street":"123 Main St."}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL