Page 1 of 1

[17.66] game.table_to_json/json_to_table

Posted: Mon Sep 02, 2019 5:08 am
by LuziferSenpai
Hey,

I wanted to use the two functions in the Title for quicky exporting/importing User saved Strings, but well it doesnt work!

So when I use table_to_json onto this table

Code: Select all

local Types =
{
	["01"] = "item",
	["02"] = "entity",
	["03"] = "technology",
	["04"] = "recipe",
	["05"] = "item-group",
	["06"] = "fluid",
	["07"] = "tile",
	["08"] = "signal",
	["09"] = "achievement"
}
its get to

Code: Select all

["item","entity","technology","recipe","item-group","fluid","tile","signal","achievement"]
But json_to_table cant read that!
And even putting it inside a String or Table doesnt work!

And even the inside Names ["01"], ["02"], ... are not put into the json.

Greetz,

Luzifer

Re: [17.66] game.table_to_json/json_to_table

Posted: Wed Sep 04, 2019 12:57 pm
by posila
Thanks for the report.
For 0.17.68 I fixed the table was interpreted as an array.

As for the other issue: json_to_table can read the result you got (I tested it to make sure), so you must have done something wrong.

Re: [17.66] game.table_to_json/json_to_table

Posted: Thu Sep 05, 2019 2:28 am
by LuziferSenpai
Hey,

I tried it again, now the table_to_json is working good, but if I do this Command for json_to_table it wont work.

Code: Select all

/c

local t = game.json_to_table( {"01":{"01":"item","02":"entity","03":"technology","04":"recipe","05":"item-group","06":"fluid","07":"tile","08":"signal","09":"achievement"},"02":"entity","03":"technology","04":"recipe","05":"item-group","06":"fluid","07":"tile","08":"signal","09":"achievement"} )

game.game.write_file( "test.txt", serpent.block( t, { sortkeys = false } ) )

Re: [17.66] game.table_to_json/json_to_table

Posted: Thu Sep 05, 2019 5:29 am
by DaveMcW
Works for me, after I fix your syntax errors.

Code: Select all

/c

t = game.json_to_table( '{"01":{"01":"item","02":"entity","03":"technology","04":"recipe","05":"item-group","06":"fluid","07":"tile","08":"signal","09":"achievement"},"02":"entity","03":"technology","04":"recipe","05":"item-group","06":"fluid","07":"tile","08":"signal","09":"achievement"}' )

game.write_file( "test.txt", serpent.block( t, { sortkeys = false } ) )

Re: [17.66] game.table_to_json/json_to_table

Posted: Thu Sep 05, 2019 7:00 am
by LuziferSenpai
DaveMcW wrote:
Thu Sep 05, 2019 5:29 am
Works for me, after I fix your syntax errors.

Code: Select all

/c

t = game.json_to_table( '{"01":{"01":"item","02":"entity","03":"technology","04":"recipe","05":"item-group","06":"fluid","07":"tile","08":"signal","09":"achievement"},"02":"entity","03":"technology","04":"recipe","05":"item-group","06":"fluid","07":"tile","08":"signal","09":"achievement"}' )

game.write_file( "test.txt", serpent.block( t, { sortkeys = false } ) )
Yea, forgot that we have ' ...