Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 816 Bytes

README.md

File metadata and controls

39 lines (32 loc) · 816 Bytes

gojsonexplode

What is gojsonexplode?

gojsonexplode go library to flatten/explode nested JSON.

How does it work?

package main

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}