json

package module
v0.0.0-...-2b3cdcb Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: Unlicense Imports: 4 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package json is a simple JSON encoder/decoder for gopher-lua.

Documentation

The following functions are exposed by the library:

decode(string):   Decodes a JSON string. Returns nil and an error string if
                  the string could not be decoded.
encode(value):    Encodes a value into a JSON string. Returns nil and an error
                  string if the value could not be encoded.
fromYAML(string): Decodes a YAML string. Returns nil and an error string if
                  the string could not be decoded.
toYAML(value):    Encodes a value into a YAML string. Returns nil and an error
                  string if the value could not be encoded.

The following types are supported:

Lua      | JSON/YAML
---------+----------
nil      | null
number   | number
string   | string
table    | object: when table is non-empty and has only string keys
         | array:  when table is empty, or has only sequential numeric keys
         |         starting from 1

Attempting to encode any other Lua type will result in an error.

Example

Below is an example usage of the library:

import (
    luajson "github.com/projectsveltos/lua-utils/glua-json"
)

L := lua.NewState()
luajson.Preload(L)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(L *lua.LState, data []byte) (lua.LValue, error)

Decode converts the JSON encoded data to Lua values.

func DecodeValue

func DecodeValue(L *lua.LState, value any) lua.LValue

DecodeValue converts the value to a Lua value.

This function only converts values that the encoding/json package decodes to. All other values will return lua.LNil.

func Encode

func Encode(value lua.LValue) ([]byte, error)

Encode returns the JSON encoding of value.

func FromYAML

func FromYAML(L *lua.LState, data []byte) (lua.LValue, error)

FromYAML converts the YAML encoded data to Lua values.

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Preload

func Preload(L *lua.LState)

Preload adds json to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local json = require("json")

func ToYAML

func ToYAML(value lua.LValue) ([]byte, error)

ToYAML returns the YAML encoding of value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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