-
-
Notifications
You must be signed in to change notification settings - Fork 5
ExportJson
Anthony Headley edited this page Jul 9, 2020
·
5 revisions
Exports a text file in JSON format of the specified data to the selected file name.
❓ Seems to not write to Internal disk.
⚠ as of 1.1.4.2 does not seem to export valid JSON, as an example:
local payload = {one = "", two = true}
ExportJson("c:\\File.json", payload)
exports:
{
one:""
two:true
}
but should be:
{
"one":""
"two":true
}
Name | Description | Optional |
---|---|---|
string : filename | The full path and file name to store the file. Should grab the path using one of the methods in the example since paths differ depending on drive and operating system. | |
table : data | The data you want to save to disk |
⚠ Should return bool but seems to always return nil
bool : true = Success writing file bool : true = Failed to write file
local filename = "ExportFile.JSON"
local drives = Root().Temp.DriveCollect
local sep = GetPathSeparator()
local selectedDrive -- users selected drive
local options = {} -- popup options
-- data to store, three levels of tables
local data = {
"Level 1.1",
"Level 1.2",
{
"Level 2.1",
"Level 2.2",
{
"Level 3.1",
"Level 3.2"
}
}
}
-- grab a list of connected drives
for i = 1, drives.count , 1 do
table.insert(options, string.format("%s (%s)", drives[i].name, drives[i].DriveType))
end
-- present a popup for the user choose (Internal may not work)
selectedDrive = PopupInput("Select a disk", display_handle, options)
-- if the user cancelled then exit the plugin
if selectedDrive == nil then
return
end
-- grab the export path for the selected drive and append the filename
local exportPath = GetPathOverrideFor("export", drives[selectedDrive + 1].path) .. sep .. filename
-- export the JSON the the selected path
local result = ExportJson(exportPath, data) -- as of 1.1.3.2 always returns nil
-- sync the files to disk when done and before your user unplugs the device
SyncFS()
--written in the negative since it seems to always return nil in 1.1.3.2
if result == false then
Echo("Failed to write to " .. exportPath)
else
Echo("Wrote file to " .. exportPath)
end