All Projects → jiyinyiyong → json-lua

jiyinyiyong / json-lua

Licence: other
JSON encoder/decoder

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to json-lua

Luaformatter
Code formatter for Lua
Stars: ✭ 244 (+419.15%)
Mutual labels:  formatter
TypeNameFormatter
A small .NET library for formatting type names à la C#.
Stars: ✭ 26 (-44.68%)
Mutual labels:  formatter
awesome-python-code-formatters
A curated list of awesome Python code formatters
Stars: ✭ 168 (+257.45%)
Mutual labels:  formatter
Mbeautifier
MBeautifier is a MATLAB source code formatter, beautifier. It can be used directly in the MATLAB Editor and it is configurable.
Stars: ✭ 248 (+427.66%)
Mutual labels:  formatter
blackbricks
Black for Databricks notebooks
Stars: ✭ 40 (-14.89%)
Mutual labels:  formatter
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (-29.79%)
Mutual labels:  formatter
Prettyhtml
💅 The formatter for the modern web https://prettyhtml.netlify.com/
Stars: ✭ 241 (+412.77%)
Mutual labels:  formatter
uck
숫자 -> 한글 단위 변환 모듈
Stars: ✭ 27 (-42.55%)
Mutual labels:  formatter
fixjson
JSON Fixer for Humans using (relaxed) JSON5
Stars: ✭ 96 (+104.26%)
Mutual labels:  formatter
ISO8601
🎗 Super lightweight ISO8601 Date Formatter in Swift
Stars: ✭ 20 (-57.45%)
Mutual labels:  formatter
Best Of Python Dev
🏆 A ranked list of awesome python developer tools and libraries. Updated weekly.
Stars: ✭ 243 (+417.02%)
Mutual labels:  formatter
idea-uroborosql-formatter
Beautiful SQL Formatter for IntelliJ Platform
Stars: ✭ 18 (-61.7%)
Mutual labels:  formatter
sql-formatter
Polyglot SQL formatter
Stars: ✭ 28 (-40.43%)
Mutual labels:  formatter
Formatting
Type-safe, functional string formatting in Swift.
Stars: ✭ 248 (+427.66%)
Mutual labels:  formatter
vscode-qiniu-upload-image
一个VS Code插件,写Markdown时可以快捷上传本地图片获取七牛图床外链。
Stars: ✭ 87 (+85.11%)
Mutual labels:  formatter
Typescript Express Starter
🚀 TypeScript Express Starter
Stars: ✭ 238 (+406.38%)
Mutual labels:  formatter
palantir-java-format
A modern, lambda-friendly, 120 character Java formatter.
Stars: ✭ 203 (+331.91%)
Mutual labels:  formatter
TcBlack
Opnionated code formatter for TwinCAT.
Stars: ✭ 67 (+42.55%)
Mutual labels:  formatter
dart-more
More Dart — Literally.
Stars: ✭ 81 (+72.34%)
Mutual labels:  formatter
rust-phonenumber
Library for parsing, formatting and validating international phone numbers.
Stars: ✭ 99 (+110.64%)
Mutual labels:  formatter

JSON.lua

This project was originally created by Jeffrey Friedl: http://regex.info/blog/lua/json

This repo is forked for LuaRocks.

Usage

By running Luarocks you will actually get a /usr/local/share/lua/5.2/JSON.lua.

luarocks install json-lua

And then you may import code like this:

JSON = require("JSON")
inspect = require("inspect")

local raw_json_text = "[1,2,[3,4]]"

local lua_value = JSON:decode(raw_json_text) -- decode example
local raw_json_text    = JSON:encode(lua_value)        -- encode example
local pretty_json_text = JSON:encode_pretty(lua_value) -- "pretty printed" version

print(inspect(lua_value))
print(inspect(raw_json_text))
print(inspect(pretty_json_text))

Output:

{ 1, 2, { 3, 4 } }
"[1,2,[3,4]]"
"[ 1, 2, [ 3, 4 ] ]"

Notice that encode_pretty is not indented style. And it's a bug need to be fixed.

array_newline option

local pretty_json_text = JSON:encode_pretty(lua_value, nil, 
           { pretty = true, align_keys = false, array_newline = true, indent = "|   " })
print(pretty_json_text)

Output:

[
|   1,
|   2,
|   [
|   |   3,
|   |   4
|   ]
]

Test

lua test.lua

License

http://creativecommons.org/licenses/by/3.0/deed.en_US

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].