additionaljson

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

go-additional-json

Example

package main

import (
	"fmt"
	"github.com/leberKleber/go-additional-json"
	"os"
)

func main() {
	s := struct {
		ID          int    `json:"id"`
		Name        string `json:"name"`
		Description struct {
			Short string `json:"short"`
			Long  string `json:"long"`
		} `json:"description"`
		Other map[string]string      `json:"-" aj:"other"`
	}{}

	j := `{
		"id": 54321,
		"name": "NaMe",
		"description": {
			"short": "short",
			"long": "lloonngg"
		},
		"other1": "ootthheerr11",
		"other2": "ootthheerr22"
	}`

	err := additionaljson.DefaultUnmarshaler.Unmarshal([]byte(j), &s)
	if err != nil {
		fmt.Printf("a error ocurred: %s", err)
		os.Exit(1)
	}

	fmt.Printf("unmarshaled:\n%v", s)
}

Output:

unmarshaled:
{54321 NaMe {short lloonngg} map[other1:ootthheerr11 other2:ootthheerr22]}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultUnmarshaler = Unmarshaler{UnmarshalFunc: json.Unmarshal}
View Source
var UnexpectedTypeErr = errors.New("failed to unmarshal json: interface to unmarshal into must be a pointer to a struct")

Functions

This section is empty.

Types

type Unmarshaler

type Unmarshaler struct {
	UnmarshalFunc func([]byte, interface{}) error
}

func (Unmarshaler) Unmarshal

func (um Unmarshaler) Unmarshal(data []byte, i interface{}) error

Jump to

Keyboard shortcuts

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