Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 1.1 KB

README.org

File metadata and controls

45 lines (36 loc) · 1.1 KB

https://mholt.github.io/json-to-go/resources/images/json-to-go.png

About

https://godoc.org/github.com/kumakichi/json-to-go?status.png

This is a reimplementation of json-to-go, which is originally developed by mholt using javascript

How to use

package main

import (
    "github.com/kumakichi/json-to-go"
    "log"
)

func main() {
    result, err := json_to_go.Parse(testData)
    if err != nil {
        log.Fatal(err)
    }
    println(result)

    result, err = json_to_go.Parse(testData, json_to_go.Options{TypeName: "rootName", Flatten: true})
    if err != nil {
        log.Fatal(err)
    }
    println(result)
}

var (
    testData = `{
      "name": {"first": "Tom", "last": "Anderson"},
      "age":37,
      "score": 92.0,
      "children": ["Sara","Alex","Jack"],
      "friends": [
        {"first": "James", "last": "Murphy"},
        {"first": "Roger", "last": "Craig"}
      ]
    }`
)