HttpsService:JSONEncode code sample fails on runtime due to arbitrary codeblock discriminator

The code sample located on the HttpService:JSONEncode page will fail on runtime due to arbitrary codeblock discriminator located on lines 1 and 28.

Images

image

image

Error

image


Solution: Remove the code discriminators from lines 1 and 28.

Corrected sample
local HttpService = game:GetService("HttpService")
     
local tab = {
    -- Remember: these lines are equivalent
    ["message"] = "succes";
    message = "success";
    	
    info = {
    	points = 120,
    	isLeader = true,
    	user = {
    		id = 12345,
    		name = "JohnDoe"
    	},
    	past_scores = {50, 42, 95},
    	best_friend = nil
    }
}
     
-- A cyclic relationship like this...
tab.tab = tab
-- ...will be replaced with the string:
-- '* certain entries belong to the same table '*
     
local json = HttpService:JSONEncode(tab)
print(json)