mapslice

package module
Version: v0.0.0-...-22c8edf Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: Apache-2.0 Imports: 4 Imported by: 1

README

GoDoc Go Report Card License Coverage Status Build Status

mapslice-json

Go MapSlice for ordered marshal/ unmarshal of maps in JSON

Example

package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/ake-persson/mapslice-json"
)

func main() {
	ms := mapslice.MapSlice{
		mapslice.MapItem{Key: "abc", Value: 123},
		mapslice.MapItem{Key: "def", Value: 456},
		mapslice.MapItem{Key: "ghi", Value: 789},
	}

	b, err := json.Marshal(ms)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(b))

	ms = mapslice.MapSlice{}
	if err := json.Unmarshal(b, &ms); err != nil {
		log.Fatal(err)
	}

	fmt.Println(ms)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapItem

type MapItem struct {
	Key, Value interface{}
	// contains filtered or unexported fields
}

MapItem representation of one map item.

func (MapItem) String

func (mi MapItem) String() string

MapItem as a string.

func (*MapItem) UnmarshalJSON

func (mi *MapItem) UnmarshalJSON(b []byte) error

UnmarshalJSON for map item.

type MapSlice

type MapSlice []MapItem

MapSlice of map items.

func (MapSlice) Len

func (ms MapSlice) Len() int

func (MapSlice) Less

func (ms MapSlice) Less(i, j int) bool

func (MapSlice) MarshalJSON

func (ms MapSlice) MarshalJSON() ([]byte, error)

MarshalJSON for map slice.

func (MapSlice) Swap

func (ms MapSlice) Swap(i, j int)

func (*MapSlice) UnmarshalJSON

func (ms *MapSlice) UnmarshalJSON(b []byte) error

UnmarshalJSON for map slice.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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