Okay. I am making a serialize function that parses data on the server into something readable and communicable to the client. In more understandable language, I am removing all the magical functions and metatables from a table and putting all the raw data in one simplified table.

For example, Take this table:

local tab = {
	["doSomething"] = function() print("I did something"); end,
	["value"] = 1234,
	["string"] = "Hello World",
	["otherTable"] = someOtherTable;
}

This table has 4 members: doSomething -- A function, value -- a number, string --a String (of letters/numbers/other things),and otherTable -- a reference to another table. Let's assume that table is

local someOtherTable = {
	--Stuff
}

When I "Serialize" this table, I make a table that looks like this:

local tab = {
	["doSomething"] = nil,
	["value"] = 1234,
	["string"] = "Hello World",
	["otherTable"] = {"Key:1"};
}

As you can see, the function was eliminated, the number and string values were kept, and the table reference was made into... another table?! This other table is a key that helps me grab that table later. Let's just say I've got all the other tables stored in a lockbox that needs a key to access.

BUT THE KEY IS INSIDE OF THE TABLE! WHY NOT JUST USE THAT?

The key is a string, and because there are other strings being sent, I do not want to mix up data. If I were to use the table after it were serialized, to find any data in the table that should be another table reference, I'd have to be checking every string:

for k, v in pairs(SerializedTable) do
	if type(v) == "string" then
		if v:match("Key") then  --or something like this
			--use key to find table	
		end
	end
end

However, if I used a table enclosed inside the table, I'd simply be checking all table objects:

for k, v in pairs(SerializedTable) do
	if type(v) == "table" then
		local key = v[1]
		--use key to find table
	end
end

It is desireable that Strings are kept simply as strings (not keys for tables) so that the strings can include anything they want. If the word "Key" was used in some ordinary string, then it would be mistaken as a table reference.

However, using tables to encapsulate things takes an unnecessary amount of data. If this data is being "serialized" it is so it can be transmitted over a server. More data transmission = more lag in the long run.

How can I come up with a more efficient way of singling out unique data rather than wrapping them in a table?