This is a JSON encoder and decoder for Hollywood MAL (https://www.hollywood-mal.com) written in the Hollywood language.
It is a port/conversion of the json.lua library which can be found here: https://github.com/rxi/json.lua Thanks guys for your work!
The conversion of the decode part was done by Christophe Gouiran (bechris13250@gmail.com) and can be found on the Official Hollywood forums Thanks a lot, Christophe! The decode part was modified a bit so it better suits the overall structure of the file.
I will try to keep this repo in sync with development that happens in the json.lua project. Please ping me or open an issue if I am behind.
Download json.hws, drop it into an existing project and include it:
@INCLUDE "json.hws"The library provides the following functions:
Returns a string representing value encoded in JSON.
json.encode({ 1, 2, 3, { x = 10 } }) ;-- Returns '[1,2,3,{"x": 10}]'Alternatively you can also use the call json_encode(value) instead.
Returns a value representing the decoded JSON string.
json.decode('[1,2,3,{"x":10}]') ;-- Returns { 1, 2, 3, { x = 10 } }Alternatively you can also use the call json_decode(str) instead.
Pretty prints a value like a decoded string to the debug output.
json.debug({ 1, 2, 3, { x = 10 } })- Trying to encode values which are unrepresentable in JSON will never result in type conversion or other magic: sparse arrays, tables with mixed key types or invalid numbers (NaN, -inf, inf) will raise an error
nullvalues contained within an array or object are converted toniland are therefore lost upon decoding- Due to Hollywood's handling of boolean values, unfortunately it is not possible to encode those values as
true/false. Insteadtrueis converted to1in the encoded format andfalseto0. - Pretty encoding is not (yet) supported,
json.encode()only encodes to a compact format
- Christophe Gouiran (decode port)
- Kevin 'invent' Saunders (logo gfx): Support Kevin's awesome work
This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.
