jsondecoder

package
v3.2.18 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnmarshalSlice

func UnmarshalSlice(data []byte, v any) error

UnmarshalSlice is a function that parses JSON data into a slice of the provided interface. It handles the case where the input data is not a JSON array by wrapping it in an array.

Examples:

data := []byte(`{"name": "Bob"}`)
var result []map[string]any
err := UnmarshalSlice(data, &result)
// result is now [{"name": "Bob"}]

data := []byte(`{"name": "Bob"}`)
var result []map[string]string
err := UnmarshalSlice(data, &result)
// result is now [{"name": "Bob"}]

data := []byte(`{"name": "Bob"}`)
var result []any
err := UnmarshalSlice(data, &result)
// result is now [{"name": "Bob"}]

data := []byte(`{"name": "Bob"}`)
var result []map[string]string
err := UnmarshalSlice(data, &result)
// result is now [{"name": "Bob"}]
// NOTE: if the input data is not a JSON array, it is wrapped in an array before decoding

Types

This section is empty.

Jump to

Keyboard shortcuts

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