English Echo JSON string

3 replies
Goto Page
To the start Previous 1 Next To the start
19.04.20 07:02:19 am
Up
Devil-Thanh
GAME BANNED
Offline Off
Guys, is there any ways to echo the JSON string using cs2d cmd echo ?

Output in console should be like: {"key":"value"}
19.04.20 12:37:00 pm
Up
VADemon
User
Offline Off
If you have the JSON as a string you can output it already. If you have a table with data then use any JSON library to encode the data as JSON and then print it.
19.04.20 01:03:42 pm
Up
Devil-Thanh
GAME BANNED
Offline Off
The point is I cam not echo the quote with cs2d cmd echo
Does the print or io.write of lua can output to cs2d_dedicated console?
19.04.20 03:51:15 pm
Up
MikuAuahDark
User
Offline Off
First, download this JSON.lua then place it in sys/lua.

The usage is something like this

Code:
1
2
3
4
5
6
7
8
local JSON = require("JSON")

local data = {
     hello = "World",
     another = "World",
     MikuAuahDark = "Test"
}
print(JSON:encode(data))


You'll get output similar (the key-value is not ordered) like this
Code:
1
{"hello":"World","another":"World","MikuAuahDark":"Test"}


print and io.write can write to cs2d_dedicated console yes.
file cs2d LuaJIT for Dedicated Server (13) JIT POWER! | Know your Lua errors! | Part of LÖVE development team since 11.3
To the start Previous 1 Next To the start