[Discontinued] JSON encoder, decoder and raw data exporter deprecated


Export data.raw of prototypes like recipes, entities and items to JSON files for tools external to the game like web sites and provide JSON services to other mods.

7 years ago
0.14 - 0.15
5
Owner:
OhChirpy
Source:
N/A
Homepage:
N/A
License:
The Unlicense (Public Domain)
Created:
7 years ago
Latest Version:
0.0.2 (7 years ago)
Factorio version:
0.14 - 0.15
Downloaded by:
5 users

Factorio JSON Tools

Notice: due to a recent change in data-raw-prototypes, which this mod uses to access raw game data for easy exporting, it will only export data that has been specifically requested at game startup time by another mod. I'm still pondering how to cope with this (switching raw access mods, doing it myself, add a function to access parsed game data instead...). The quick fix is to downgrade data-raw-prototypes back to 0.2.*.

Small mod to
1. export comprehensive raw prototype data from the game to disk in a standard format and
2. provide JSON conversion services to other mods.

Usage

From console or your mod, you can do:

remote.call("JsonTools", "export_data", {some = "data", ["to"] = ["Export", "to", "disk"]}, "mandatory_filename.json");

Convert the Lua table/number/string to JSON and write it to a file.

remote.call("JsonTools", "encode_json", data_to_encode);
remote.call("JsonTools", "decode_json", "[1, 2, {\"json\": \"is nice\"}]");

Convert data to a json string and back, for example for logging or nicer error messages than provided by Serpent.

remote.call("JsonTools", "export_all", filename, filter);

Export raw prototype data.
´filename´, if ommitted, is data-raw-all.json, and filter is either a list of prototypes you want to see, or nil to get all of them.

For example,
{{{
/c remote.call("JsonTools", "export_all", "recipes.json", {"recipe", "furnace", "assembling-machine", "fluid", "item", "technology", "module", "beacon"});
}}}
in the console will write a json file with all info needed to display in depth recipe information, including nice icons, the correct assemblers, and the technologies needed to access them.

Credits

(C)2017 OhChirpy, Unlicense or CC0

Uses json.lua by rxi, see LICENSE. Changed to allow mixed list and dictionary tables (who will end up as JSON objects with number string keys).

Uses the data-raw-prototypes mod by Earendel to see raw prototype data in control.lua without worrying about performance or out of date information.

This mod was inspired by the formidable helmod by Helfima, which showed me that it's actually possible to access this information even if the lua API docs suggest otherwise.

This mod is similar to JsonExtractor by Xyfi, but that one can only include the limited lua api view into recipes, which for example misses information on which assembler can use which recipe.

Version History

0.0.2 - 2017.04.26 - Factorio 0.15.1
Update dependencies.

0.0.1 - 2017.04.18 - Factorio 0.14.22
Initial release.