[17.66] game.table_to_json/json_to_table

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 333
Joined: Tue Jul 08, 2014 10:06 am
Contact:

[17.66] game.table_to_json/json_to_table

Post 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
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [17.66] game.table_to_json/json_to_table

Post 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.

User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 333
Joined: Tue Jul 08, 2014 10:06 am
Contact:

Re: [17.66] game.table_to_json/json_to_table

Post 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 } ) )
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [17.66] game.table_to_json/json_to_table

Post 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 } ) )

User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 333
Joined: Tue Jul 08, 2014 10:06 am
Contact:

Re: [17.66] game.table_to_json/json_to_table

Post 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 ' ...
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai

Post Reply

Return to “Resolved Problems and Bugs”