cJson
Index: Articles Classes Hooks Quick navigation: BannerPattern BossBarColor BossBarDivisionType cArrowEntity cBeaconEntity cBedEntity cBlockArea cBlockEntity cBlockEntityWithItems cBlockInfo cBoat cBoundingBox cBrewingstandEntity cChatColor cChestEntity cChunkDesc cClientHandle cColor cCommandBlockEntity cCompositeChat cCraftingGrid cCraftingRecipe cCryptoHash cCuboid cDispenserEntity cDropperEntity cDropSpenserEntity cEnchantments cEnderCrystal cEntity cEntityEffect cExpBottleEntity cExpOrb cFallingBlock cFile cFireChargeEntity cFireworkEntity cFloater cFlowerPotEntity cFurnaceEntity cGhastFireballEntity cHangingEntity cHopperEntity cIniFile cInventory cItem cItemFrame cItemGrid cItems cJson cJukeboxEntity cLeashKnot cLineBlockTracer cLuaWindow cMap cMapManager cMobHeadEntity cMobSpawnerEntity cMojangAPI cMonster cNetwork cNoteEntity cObjective cPainting cPawn cPickup cPlayer cPlugin cPluginLua cPluginManager cProjectileEntity cRankManager cRoot cScoreboard cServer cServerHandle cSignEntity cSplashPotionEntity cStringCompression cTCPLink cTeam cThrownEggEntity cThrownEnderPearlEntity cThrownSnowballEntity cTNTEntity cUDPEndpoint cUrlClient cUrlParser CustomStatistic cUUID cWebAdmin cWindow cWitherSkullEntity cWorld EffectID HTTPFormData HTTPRequest HTTPTemplateRequest ItemCategory lxp SmokeDirection sqlite3 StatisticsManager TakeDamageInfo tolua Vector3d Vector3f Vector3i Globals | Contents
cJson classExposes the Json parser and serializer available in the server. Plugins can parse Json strings into Lua tables, and serialize Lua tables into Json strings easily. Functions
Serializer optionsThe "options" parameter given to the cJson:Serialize() function is a dictionary-table of "option name" -> "option value". The serializer warns if any unknown options are used; the following options are recognized:
Code example: Parsing a Json stringThe following code, adapted from the Debuggers plugin, parses a simple Json string and verifies the results:local t1 = cJson:Parse([[{"a": 1, "b": "2", "c": [3, "4", 5]}]]) assert(t1.a == 1) assert(t1.b == "2") assert(t1.c[1] == 3) assert(t1.c[2] == "4") assert(t1.c[3] == 5) Code example: Serializing into a Json stringThe following code, adapted from the Debuggers plugin, serializes a simple Lua table into a string, using custom indentation:local s1 = cJson:Serialize({a = 1, b = "2", c = {3, "4", 5}}, {indentation = " "}) LOG("Serialization result: " .. (s1 or " |