Codectionary / Developer documentation / Luau

HttpService JSON

Encode a simple table as JSON and decode it again.

Why use HttpService?

HttpService offers JSONEncode and JSONDecode even when no external HTTP request is made. JSON is useful for exchanging plain data, but Roblox Instances and every Luau value type are not directly representable in JSON.

Try it in Roblox Studio

Put this Script in ServerScriptService and inspect Studio Output. It uses JSON methods only; no HTTP endpoint or external network permission is required.

Syntax

local text = HttpService:JSONEncode(data)
local data = HttpService:JSONDecode(text)

Examples

HttpService JSON

Round-trip a small table of plain values.

local HttpService = game:GetService("HttpService")
local profile = {name = "Alex", level = 3}
local json = HttpService:JSONEncode(profile)
print(json)
local decoded = HttpService:JSONDecode(json)
print(decoded.name, decoded.level)
  1. JSONEncode turns the supported table fields into a JSON string.
  2. JSONDecode parses that string back into a Luau table.
  3. Object property order in the encoded text is not a contract; use decoded fields by name.

Best practices

  • Validate decoded external data before trusting it.
  • Do not place secrets in client-visible JSON.

Runtime & versions

Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Luau documentation

Specifications & further reading