json

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package json is the "json" host module. See std/encoding/register.go for why this and its eight siblings each get their own leaf package instead of living in std's flat root, and how this directory's Module reaches the rest of magus without std importing back down to collect it.

Index

Constants

This section is empty.

Variables

View Source
var Module = std.Module{
	Name: "json",
	WASM: true,
	Path: "encoding/json",
	Doc:  "JSON encode/decode.",
	Methods: []std.Method{
		{
			Name:    "parse",
			Doc:     "Decode a JSON string into a value (map, list, string, number, or boolean).",
			Args:    []std.Arg{{Name: "s", Type: std.TypeString}},
			Returns: []std.Ret{{Type: std.TypeAny}},
			Raises:  true,
			Impl:    JSONParse,
		},
		{
			Name: "stringify",
			Doc:  "Encode a value as a JSON string. With no indent (or \"\") the output is compact; pass an indent string (e.g. \"  \" or \"\\t\") for pretty, multi-line output.",
			Args: []std.Arg{
				{Name: "value", Type: std.TypeAny},
				{Name: "indent", Type: std.TypeString, Optional: true},
			},
			Returns: []std.Ret{{Type: std.TypeString}},
			Raises:  true,
			Impl:    JSONStringify,
		},
	},
}

Module is the "json" host module: JSON encode/decode for spells.

Functions

func JSONParse

func JSONParse(_ context.Context, s string) (any, error)

JSONParse decodes a JSON string into a value (map, list, string, number, or boolean).

func JSONStringify

func JSONStringify(_ context.Context, value any, indent string) (string, error)

JSONStringify encodes a value as a JSON string. An empty indent (the omitted-arg case - the binding layer passes "" rather than a missing value) yields compact output; any non-empty indent selects pretty, multi-line output with that string per nesting level. The two share one entry point because "compact" is just the no-indent case, so an author has a single call to learn.

func Modules

func Modules() []std.Module

Modules returns this directory's contribution to the encoding module set. See std/encoding/register.go: it aggregates every leaf's Modules() into one slice, which is how a module here reaches std.All()'s callers without std importing this package to collect it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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