Thanks to visit codestin.com
Credit goes to github.com

Skip to content

thedolphin/lua-yyjson-nd

Repository files navigation

Summary

yyjson-nd is a Lua binding to the yyjson C library that preserves the original JSON document structure and data types by representing JSON nodes as userdata objects, creating them on demand. Conversion to Lua tables and types happens lazily on access, minimizing data loss and improving performance compared to full eager decoding (unmarshalling).

When assigning a number to a field, the library attempts to store it as an integer if possible.

JSON array creation is currently unsupported

Functions and constants

  1. load - parses JSON into a read-only document
  2. load_mut - parses JSON into a mutable document
  3. new - creates a new mutable JSON document
  4. null - null constant
  5. tostring(<mutable document>) - serializes a mutable JSON object to a string

Examples

yyjson = require("yyjson-nd")

j = yyjson.new() -- create an empty JSON document
j = yyjson.load(json_string) -- load JSON for read-only access (faster)
j = yyjson.load_mut(json_string) -- load JSON for modification

-- access fields
print(j.int32)
print(j.object.nested_object.inner_float)

-- modify and create new fields
j.uuid = nil -- delete
j.boolean = yyjson.null -- overwrite with null
j.newobject = {test = 1, test1 = {test2 = "test"}}
j.array[4] = 8 -- modify existing array
j.copy = j.object -- copy subtrees, even between different documents

-- serialize to JSON
tostring(j) -- full document
tostring(j.object) -- document part

Luarocks

Available on luarocks.org

$ luarocks install yyjson-nd

About

Non-destructive Lua wrapper for yyjson library

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors