PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. To see our new and improved documentation, please click here. You can read more about the future of documentation here.
Collapse Sidebar

JSONEncode

The JSONEncode function transforms a Lua table into a JSON object or array based on the following guidelines:

  • Keys of the table must be either strings or numbers. If a table contains both, an array takes priority (string keys are ignored).
  • An empty Lua table {} generates an empty JSON array.
  • The value nil is never generated.
  • Cyclic table references cause an error.

To reverse the encoding process, and decode a JSON object, you can use HttpService|HttpService's HttpService/JSONDecode function.

Many web endpoints use JSON, as it is commonly used on the Internet. Visit JSON.org to become more familiar with the format.

This method can be used regardless of whether HTTP Requests are HttpService/HttpEnabled|enabled.

Parameters

Name Type Default Description

The input Lua table

Returns

Return Type Summary

The returned JSON string


Code Samples


HttpService JSONEncode

This code sample turns a Lua table tab into a JSON string using HttpService’s JSONEncode. Then, it prints out the string.

Try editing the Lua table to see how the JSON output changes.