Skip to content

Commit ac84cd3

Browse files
att
1 parent b79e50a commit ac84cd3

22 files changed

Lines changed: 10804 additions & 10476 deletions

File tree

README.md

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,140 @@
11
# LuaFluidJson
2-
An json Parser for lua that doesnt require any adaptation
2+
An json Parser for lua that doesn't require any adaptation
33

44

5+
Beside others parsers that requires adaptation to load and dump jsons, these LuaFluidJson use
6+
the native mechanics of lua to implement the load and dump processing, allowing a super easy way
7+
to deal with jsons.
58

6-
s
9+
<h3 style="color:red;">THESE LIB ITS NOT PRODUCTION READY USE WITH RESPONSIBILITY</h3>
10+
11+
### Platforms supported:
12+
**Linux** (Tested on Fedora and Ubuntu)
13+
14+
### Installation
15+
The instalation doesnt require lua rocks or any package manager, just download the
16+
[download link](aaa) into your project and copy in the root of your main,and you can start using
17+
18+
### Dumping Json file
19+
these code dumps the following struct into a json file
20+
```lua
21+
local json = require("luaFluidJson/luaFluidJson")
22+
23+
local user ={
24+
25+
name='Nateus',
26+
age=27,
27+
maried=false,
28+
sons={
29+
{name='son1',maried='null'}
30+
}
31+
}
32+
local ident = true
33+
json.dumps_to_file(user,"test/target/out.json",ident);
34+
35+
```
36+
37+
### Dumping a json String
38+
if you need to dump a JSON String its also easy, you can just call the **dumps_to_string** function
39+
40+
```lua
41+
local json = require("luaFluidJson/luaFluidJson")
42+
43+
local user ={
44+
45+
name='Nateus',
46+
age=27,
47+
maried=true,
48+
sons={
49+
{name='son1',maried=false }
50+
}
51+
}
52+
local ident = true
53+
local value = json.dumps_to_string(user,ident);
54+
55+
print(value)
56+
```
57+
58+
### Loading a Json from File
59+
you can easly load a json direct from file
60+
```lua
61+
62+
local json = require("luaFluidJson/luaFluidJson")
63+
64+
65+
local parsed = json.load_from_file("test/target/element.json");
66+
67+
print("name:"..parsed.name)
68+
print("age:"..parsed.age)
69+
print("maried:"..tostring(parsed.maried))
70+
for i,v in ipairs(parsed.sons) do
71+
local son_name = v["name"]
72+
print("son name:"..son_name)
73+
end
74+
```
75+
### Loading a Json from String
76+
its also possible to load a json from string
77+
78+
```lua
79+
80+
local json = require("luaFluidJson/luaFluidJson")
81+
82+
local test = '{"name":"mateus","age":27}'
83+
84+
local parsed = json.load_from_string(test);
85+
86+
print("name:"..parsed.name)
87+
print("age:"..parsed.age)
88+
89+
```
90+
### The Null Terminator
91+
since the lua nill doesn't work as other languages "nulls" ,the lib consider null as a string
92+
so if you put "null" into your code, the lib will consider as a null value
93+
94+
```lua
95+
local json = require("luaFluidJson/luaFluidJson")
96+
97+
local user ={
98+
99+
name='Nateus',
100+
age=27,
101+
maried=false,
102+
sons='null'
103+
}
104+
local ident = true
105+
json.dumps_to_file(user,"test/target/out.json",ident);
106+
```
107+
### Null Scape
108+
its also possible to scape null putting another code into its place
109+
110+
```lua
111+
112+
local json = require("luaFluidJson/luaFluidJson")
113+
json.set_null_code("custom_null")
114+
local user ={
115+
116+
name='Nateus',
117+
age=27,
118+
maried=false,
119+
sons='custom_null'
120+
}
121+
local ident = true
122+
json.dumps_to_file(user,"test/target/out.json",ident);
123+
```
124+
125+
### Identifying objects
126+
if you want to ensure the following table will be parsed as a object, you can just call the
127+
**is_table_a_object** function
128+
129+
```lua
130+
131+
local json = require("luaFluidJson/luaFluidJson")
132+
133+
local test = {1,2,3}
134+
print(json.is_table_a_object(test))
135+
136+
local test2 = {a=20,b=30}
137+
138+
print(json.is_table_a_object(test2))
139+
140+
```

build.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ local function test_unit(unit,start_assignature)
6060
dtw.write_file(unit.."expected.txt",output)
6161
end
6262

63+
print("valgrind testing: "..file_path)
64+
os.execute("valgrind lua "..file_path.." &>> out.txt","r")
65+
local output_valgrind = dtw.load_file("out.txt")
66+
local heap_test = string.find(output_valgrind, "All heap blocks were freed ")
67+
local error_test = string.find(output_valgrind,"0 errors from 0 contexts")
68+
dtw.remove_any("out.txt")
69+
70+
if heap_test == nil or error_test == nil then
71+
print(output_valgrind)
72+
return true
73+
end
74+
75+
76+
6377

6478
local test_assignature = dtw.generate_sha_from_folder_by_content(SIDE_EFFECT)
6579
--means code generated side effect
@@ -82,7 +96,7 @@ local function exec_tests(start_assignature)
8296

8397
for i, t in ipairs(tests) do
8498
local error = test_unit(t,start_assignature)
85-
dtw.copy_any_overwriting(side_effect_copy_path,SIDE_EFFECT);
99+
dtw.copy_any_overwriting(side_effect_copy_path,SIDE_EFFECT);
86100

87101
if error then
88102
return
@@ -110,7 +124,7 @@ local function main()
110124
dtw.copy_any_overwriting(side_effect_copy_path,SIDE_EFFECT);
111125
dtw.remove_any(side_effect_copy_path)
112126

113-
-- os.execute("zip -r luaDoTheWorld.zip luaDoTheWorld/")
127+
os.execute("zip -r luaFluidJson.zip src/")
114128
end
115129

116130

saida.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)