How can I convert an instance to an json object?

I want to convert an instance with all of their properities to an json object. however when I do HttpService:JSONEncode({ players: game.Players:GetPlayers() }) it return { "players": [null, null, null, null]} so what do I need to do?

You could use this plugin:

and convert the table that was created.

Although, be mindful that certain properties (such as Position, CFrame, etc) would need to be serialized correctly before turning it into JSON data.

What do I do if I want to do it in my game. I can’t run a plugin in production in my running game

To do this in-game, you would need to send Http requests to get the most recent Roblox API dump and convert each object (you need, based off of their class) individually then combine them into a table and serialize that.

If you have BTRoblox, you can see the source code for the plugin and how it works. (It basically does what I just described)