Forum

> > CS2D > Scripts > Echo JSON string
Forums overviewCS2D overview Scripts overviewLog in to reply

English Echo JSON string

3 replies
To the start Previous 1 Next To the start

old Echo JSON string

Devil-Thanh
GAME BANNED Off Offline

Quote
Guys, is there any ways to echo the JSON string using cs2d cmd echo ?

Output in console should be like: {"key":"value"}

old Re: Echo JSON string

VADemon
User Off Offline

Quote
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.

old Re: Echo JSON string

Devil-Thanh
GAME BANNED Off Offline

Quote
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?

old Re: Echo JSON string

MikuAuahDark
User Off Offline

Quote
First, download this JSON.lua then place it in sys/lua.

The usage is something like this

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
1
{"hello":"World","another":"World","MikuAuahDark":"Test"}

print and io.write can write to cs2d_dedicated console yes.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview