{"modulePath":"github.com/projectsveltos/lua-utils/glua-json","version":"v0.0.0-20251212200258-2b3cdcb7c0f5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package json\n\nPackage json is a simple JSON encoder/decoder for gopher-lua.\n\n### Documentation {#hdr-Documentation}\n\nThe following functions are exposed by the library:\n\n\tdecode(string):   Decodes a JSON string. Returns nil and an error string if\n\t                  the string could not be decoded.\n\tencode(value):    Encodes a value into a JSON string. Returns nil and an error\n\t                  string if the value could not be encoded.\n\tfromYAML(string): Decodes a YAML string. Returns nil and an error string if\n\t                  the string could not be decoded.\n\ttoYAML(value):    Encodes a value into a YAML string. Returns nil and an error\n\t                  string if the value could not be encoded.\n\nThe following types are supported:\n\n\tLua      | JSON/YAML\n\t---------+----------\n\tnil      | null\n\tnumber   | number\n\tstring   | string\n\ttable    | object: when table is non-empty and has only string keys\n\t         | array:  when table is empty, or has only sequential numeric keys\n\t         |         starting from 1\n\nAttempting to encode any other Lua type will result in an error.\n\n### Example {#hdr-Example}\n\nBelow is an example usage of the library:\n\n\timport (\n\t    luajson \"github.com/projectsveltos/lua-utils/glua-json\"\n\t)\n\n\tL := lua.NewState()\n\tluajson.Preload(L)\n\n## Functions\n\n```go\nfunc Decode(L *lua.LState, data []byte) (lua.LValue, error)\n```\nDecode converts the JSON encoded data to Lua values.\n\n```go\nfunc DecodeValue(L *lua.LState, value any) lua.LValue\n```\nDecodeValue converts the value to a Lua value.\n\nThis function only converts values that the encoding/json package decodes to. All other values will return lua.LNil.\n\n```go\nfunc Encode(value lua.LValue) ([]byte, error)\n```\nEncode returns the JSON encoding of value.\n\n```go\nfunc FromYAML(L *lua.LState, data []byte) (lua.LValue, error)\n```\nFromYAML converts the YAML encoded data to Lua values.\n\n```go\nfunc Loader(L *lua.LState) int\n```\nLoader is the module loader function.\n\n```go\nfunc Preload(L *lua.LState)\n```\nPreload adds json to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:\n\n\tlocal json = require(\"json\")\n\n```go\nfunc ToYAML(value lua.LValue) ([]byte, error)\n```\nToYAML returns the YAML encoding of value.\n\n","path":"github.com/projectsveltos/lua-utils/glua-json","name":"json","synopsis":"Package json is a simple JSON encoder/decoder for gopher-lua.","isRedistributable":true}
