SCRIPT ERROR: type 'function' is not supported by JSON: fix
This error means a Lua table with a function was passed to json.encode. Remove the function, or replace it with plain data, then test again.
Short answer: The error means your script passed a Lua table to json.encode, and that table holds a function. JSON cannot store functions. Remove the function from the table, or replace it with plain data such as a string, and run the action again.
Last checked: 2026-12-02.
What the error means
The message SCRIPT ERROR: type 'function' is not supported by JSON comes from the JSON encoder. When it reaches a value of type function, it stops. The problem is in the table you give to the encoder, not in the encoder itself. A cfx.re forum answer for this error says the same: remove the function, and the error goes away.
Steps to fix it
- Find the json.encode call. Open the script that raised the error and search for
json.encode. Check which table it encodes. - Look for functions in that table. Check every key and value. A key with the value
function() ... endis the problem. You will find it as a line likemyFunction = function() ... endinside the table. - Remove the function or replace it. Take the function out of the table before you encode it. If the data needs to hold a name, store a string instead.
```lua -- Before: the function makes json.encode fail local data = { name = "John", onSave = function() print("saved") end, }
-- After: only plain values are encoded local data = { name = "John", } local text = json.encode(data) ```
- Run the action again. Restart the resource, then repeat the action that failed, for example the command that triggered the error.
Verify the fix
Run the same action again. The type 'function' is not supported by JSON message should not appear in the console, and the action should finish.
If it does not work
- Check nested tables. A function can sit several levels deep inside the table you encode.
- Check tables that come from other code. A table returned by another resource or library may hold functions too, so inspect it before you encode it.
- Make sure you encode the data, not the function. The error only appears when a function is inside the value you pass to
json.encode.
Frequently asked questions
Does this error mean my server is broken?
No. It is a bug in the script that builds the table. Fix that script and the server works again.
Can I change json.encode so it skips functions?
The forum answer does not suggest that. It removes the function from the table instead, so start there.
Why does JSON not accept functions?
JSON stores only text, numbers, booleans, null, arrays and objects. A function is code, so JSON has no way to store it.
Sources
- [cfx.re forum: [SOLVED] script:chat SCRIPT ERROR: type 'function' is not supported by JSON](https://forum.cfx.re/t/solved-script-chat-script-error-type-function-is-not-supported-by-json-problem-when-i-use-setjob/5166058)
FiveM.tools was founded with sponsorship from Nyru.