Skip to content
This repository was archived by the owner on Nov 28, 2018. It is now read-only.

NexusInstruments/JsonUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JsonUtils

A Wildstar Embeded LUA library to Decode/Encode JSON data - LUA tables.

This can be very helpful when needing to export or save data inside the add-on data storage/settings. Or useful when you want to transport encoded data between add-ons or between clients through the use of in-game comm-channels.

Usage

Embedding

  Apollo.GetPackage("Json:Utils-1.0").tPackage:Embed(self)

  self:JSONEncode({ a = 1 })

JSONDecode

Example

  Apollo.GetPackage("Json:Utils-1.0").tPackage:Embed(self)

  local jsonStr = "[{\"a\":1,\"b\":\"string\",\"c\":{\"a\":1,\"b\":\"string\"},\"d\":null}]"

  local tNewTable = self:JSONDecode(jsonStr)

Results

Value of tNewTable:
{
    a = 1,
    b = "string",
    c = { a = 1, b = "string" }
    d = nil
}

JSONEncode

Example

  Apollo.GetPackage("Json:Utils-1.0").tPackage:Embed(self)

  local tNewTable = {
    a = 1,
    b = "string",
    c = { a = 1, b = "string" }
    d = nil
  }

  local exportStr = self:JSONEncode(tNewTable)

Results

[{"a":1,"b":"string","c":{"a":1,"b":"string"},"d":null}]

JSONEncodePretty

Example

  Apollo.GetPackage("Json:Utils-1.0").tPackage:Embed(self)

  local tNewTable = {
    a = 1,
    b = "string",
    c = { a = 1, b = "string" }
    d = nil
  }

  local exportStr = self:JSONEncodePretty(tNewTable)

Results

[
  {
    "a": 1,
  "b": "string",
  "c": {
    "a": 1,
    "b": "string"
  },
  "d": null
  }
]

Portions of this library's code attributed to:

 JSON-Lua Copyright 2010-2013 Jeffrey Friedl
 http://regex.info/blog/
 Latest version: http://regex.info/blog/lua/json
 Released under a Creative Commons CC-BY "Attribution" License:
 http://creativecommons.org/licenses/by/3.0/deed.en_US

Licensed under MIT License Copyright (c) 2015 NexusInstruments

About

A Wildstar Embeded LUA library to Encode LUA objects into JSON strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages