main.go 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/ipld/go-ipld-prime/codec/dagjson"
	"github.com/ipld/go-ipld-prime/codec/jst"
	basicnode "github.com/ipld/go-ipld-prime/node/basic"
)

func main() {
	fixture := `[
		{"path": "./foo",  "moduleName": "whiz.org/teamBar/foo", "status": "changed"},
		{"path": "./baz",  "moduleName": "whiz.org/teamBar/baz", "status": "green"},
		{"path": "./quxx", "moduleName": "example.net/quxx",     "status": "lit",
		  "subtable": [
		    {"widget": "shining",       "property": "neat", "familiarity": 14},
		    {"widget": "shimmering",    "property": "neat", "familiarity": 140},
		    {"widget": "scintillating",                     "familiarity": 0},
		    {"widget": "irridescent",   "property": "yes"},
		  ]}
	]`
25
	nb := basicnode.Prototype.Any.NewBuilder()
26 27 28 29 30 31 32 33 34 35 36 37 38 39
	if err := dagjson.Decoder(nb, bytes.NewBufferString(fixture)); err != nil {
		panic(err)
	}
	n := nb.Build()

	if err := jst.MarshalConfigured(jst.Config{
		Indent: []byte{' ', ' '},
		Color:  jst.Color{Enabled: true},
	}, n, os.Stdout); err != nil {
		fmt.Printf("\nerror: %s\n", err)
		os.Exit(5)
	}
	fmt.Println()
}