I am going create a pr and get these packages added. I guess I should have started with the problem with the current luci.jsonc in my use case, and demonstrate how jsonmg does not have the same issues dealing with complex JSON input.
So you may or may not have notice the kasalua libraby on my git. It is a full blown interfacing library to interact with all (any i have tested) kasa smart devices. You can scan you local network for devices, control kasa smart plugs, wall plugs, smart switches(power bars), dimmer switchs, light switches and smart bulbs (I do not own a light strip to test but they should be work fine aswell). Anyhow, when scanning for or interacting with the devices, the devices communicate thru tcp, the payloads are encrypted json objects, once decrypted the the json data ranges in size from about 500 -> 2048byes. Now i began the project with the intentions of using luci.jsonc to covert the json to lua, perform what ever tasks needed on the data in lua, then convert the lua back to JSON notation to be display on a web page or whatever the case.
This worked great, luci.jsonc performs like a champ in simple parsing of the payload, however, problems began when trying to add data to the converted json payload in lua, or more accurately, well converting the data back from lua to json. Much of the data gets lost ... or is ignored
example 1
hostle@dani:~/kasalua/kasalua/src$ ./test-jsonmg.lua
BROADCASTING ON IP: 10.0.10.174
1 table 0x56f644c82840
2 number 1
3 table 0x56f644c82890
1 table 0x56f644c82840
1 table 0x56f644c82840
BROADCASTING ON IP: 10.0.10.174
1 table 0x56f644c82ce0
2 number 1
3 table 0x56f644c82d30
1 table 0x56f644c82ce0
1 table 0x56f644c82ce0
jsonmg
TP-LINK_Power Strip_0A7D
luci.jsonc
TP-LINK_Power Strip_0A7D
jsonmg
0000000000000000000000000000000000000000 //<-- deviceId
luci.jsonc
0000000000000000000000000000000000000000 //<--deviceId
jsonmg
{"sysinfo":"{"system":{"get_sysinfo":{"sw_ver":"1.0.8 Build 230804 Rel.172306","hw_ver":"2.0","model":"KP303(US)","deviceId":"0000000000000000000000000000000000000000","oemId":"00000000000000000000000000000000","hwId":"00000000000000000000000000000000","rssi":-52,"latitude_i":-1879048193,"longitude_i":-1879048193,"alias":"TP-LINK_Power Strip_0A7D","status":"new","obd_src":"tplink","mic_type":"IOT.SMARTPLUGSWITCH","feature":"TIM","mac":"AA:BB:CC:DD:EE:FF","updating":0,"led_off":0,"children":[{"id":"00","state":1,"alias":"EXHAUST FAN","on_time":34739,"next_action":{"type":1,"schd_sec":82800,"action":0}},{"id":"01","state":1,"alias":"Light1","on_time":34727,"next_action":{"type":1,"schd_sec":82800,"action":0}},{"id":"02","state":1,"alias":"HUMIDIFIER","on_time":8426,"next_action":{"type":1,"schd_sec":82800,"action":0}}],"child_num":3,"ntc_state":0,"err_code":0}}}","ip":"10.0.10.174"}
luci.jsonc
{"sysinfo":"{\"system\":{\"get_sysinfo\":{\"sw_ver\":\"1.0.8 Build 230804 Rel.172306\",\"hw_ver\":\"2.0\",\"model\":\"KP303(US)\",\"deviceId\":\"0000000000000000000000000000000000000000\",\"oemId\":\"00000000000000000000000000000000\",\"hwId\":\"00000000000000000000000000000000\",\"rssi\":-52,\"latitude_i\":-1879048193,\"longitude_i\":-1879048193,\"alias\":\"TP-LINK_Power Strip_0A7D\",\"status\":\"new\",\"obd_src\":\"tplink\",\"mic_type\":\"IOT.SMARTPLUGSWITCH\",\"feature\":\"TIM\",\"mac\":\"AA:BB:CC:DD:EE:FF\",\"updating\":0,\"led_off\":0,\"children\":[{\"id\":\"00\",\"state\":1,\"alias\":\"EXHAUST FAN\",\"on_time\":34739,\"next_action\":{\"type\":1,\"schd_sec\":82800,\"action\":0}},{\"id\":\"01\",\"state\":1,\"alias\":\"Light1\",\"on_time\":34727,\"next_action\":{\"type\":1,\"schd_sec\":82800,\"action\":0}},{\"id\":\"02\",\"state\":1,\"alias\":\"HUMIDIFIER\",\"on_time\":8426,\"next_action\":{\"type\":1,\"schd_sec\":82800,\"action\":0}}],\"child_num\":3,\"ntc_state\":0,\"err_code\":0}}}","ip":"10.0.10.174"
So far so good. Other than luci.jsonc not un-escaping the string, the results are even ..or both correct, valid json. But there is a subtle isusse, notice the ip is enclosed in(part of the json object) in the jsonmg output. Though its not wrong or very difficult to deal with post conversion, its not correct, or as i intended it to be. jsonmg on the other hand outputs the JSON in the CORRECT format.
now image you, need to add some critical JSON data to the output. lets use a variety of json type this time..
data is the jsonmg converted json and data2 is the jsonc conveted data, respectively.
data.foo = "bar"; //<-- array string
data2.foo = "bar";
data.bar = "foo";
data2.bar = "foo";
data.foo2 = {bill = "ted", dean = {dallas = "car"}}; //<-- a nested object
data2.foo2 = {bill = "ted", dean = {dallas = "car"}};
data.foo3 = {big = "rink"}; //<-- kv pair
data2.foo3 = {big = "rink"};
data.arr2 = {"bill", "ted", "bogus", "journey", {1,2,3,4,5,6, cheech = {chong = 2}}} <-- array with nested array + nested object
data.fun = function() print("hello") end; //<-- simple function to print hello
data[1]="reall??"; //<-- another array string
data2.fun = function() print("hello") end;
results
JSONC: {"1":1,"2":2,"3":3,"4":4,"5":5,"6":"test","7":{"testy":{"joe":"woods"}},"8":{"frank":"black"},"foo3":{"big":"rink"},"foo2":{"dean":{"dallas":"car"},"bill":"ted"},"fun":null,"bar":"foo","foo":"bar"}
JSONMG {"1":"reall??","arr2":["bill","ted","bogus","journey",[1,2,3,4,5,6,{"cheech":{"chong":2}}]],"foo3":{"big":"rink"},"foo2":{"dean":{"dallas":"car"},"bill":"ted"},"sysinfo":{"system":{"get_SysInfo":{"obd_src":"tplink","rssi":-46,"feature":"TIM","hw_ver":"2.0","alias":"TP-LINK_Power Strip_0A7D","mac":"AA:BB:CC:DD:EE:FF","err_code":0,"ntc_state":0,"child_num":3,"children":[{"state":1,"next_action":{"schd_sec":82800,"parent_type":1,"action":0},"id":"000000000000000000000000000000000000000000","alias":"EXHAUST FAN","on_time":1},{"state":0,"next_action":{"schd_sec":82800,"parent_type":1,"action":0},"id":"000000000000000000000000000000000000000000","alias":"Light1","on_time":1},{"state":1,"next_action":{"schd_sec":82800,"parent_type":1,"action":0},"id":"000000000000000000000000000000000000000000","alias":"HUMIDIFIER","on_time":2}],"updating":0,"led_off":0,"deviceId":"0000000000000000000000000000000000000000","longitude_i":-1879048193,"latitude_i":-1879048193,"status":"new","model":"KP303(US)","mic_TYPE":"IOT.SMARTPLUGSWITCH","oemId":"00000000000000000000000000000000","hwId":"00000000000000000000000000000000","sw_ver":"1.0.8 Build 230804 Rel.172306"}}},"bar":"foo","foo":"bar","ip":"10.0.10.174"}