JSONedit: preprocessor (Lua scripting)
JSONedit 0.9.16 introduced text preprocessing using Lua scripting. This function allows to pass text entered in tree view through Lua before using it. Initially it was intended for tasks that were simple (converting characters to lowercase, removing accidentally entered newlines) yet too specific to add to application itself, but it can potentially do more complex processing like creating text shortcuts that expand to full text with Lua.
JSONedit uses two separate scripts: for node name nad for node value preprocessing. They must be placed in application directory.
Example: InputNamePreprocessor.lua
inputString = GetInputText() -- required: read input string -- print(string.format("inputString = %s\n", inputString)) -- convert to lowercase outputString = string.lower(inputString) -- remove newlines outputString = string.gsub(outputString, "\r", "") outputString = string.gsub(outputString, "\n", "") -- print(string.format("outputString = %s\n", outputString)) SetOutputText(outputString) -- required: set output string
Example: InputValuePreprocessor.lua
inputString = GetInputText() -- required: read input string inputType = GetInputValueType() if inputType == 3 then -- combobox type index; 3 = string do -- print(string.format("inputString = %s\n", inputString)) -- convert to lowercase outputString = string.lower(inputString) -- remove newlines outputString = string.gsub(outputString, "\r", "") outputString = string.gsub(outputString, "\n", "") end else do outputString = inputString; end end -- print(string.format("outputString = %s\n", outputString)) SetOutputText(outputString) -- required: set output string
Example: InputNamePreprocessor.lua - simple text substitution / expanding / autocorrect
inputString = GetInputText() -- required: read input string -- print(string.format("inputString = %s\n", inputString)) -- convert to lowercase outputString = inputString -- default value tmpString = string.lower(inputString) substitutions = { ["alin"] = "Abraham Lincoln", ["abelin"] = "Abraham Lincoln", ["gwash"] = "George Washington", ["jada"] = "John Adams", ["tjef"] = "Thomas Jefferson" } if (substitutions[tmpString] ~= nil) then outputString = substitutions[tmpString] end -- print(string.format("outputString = %s\n", outputString)) SetOutputText(outputString) -- required: set output string
Note: scripts are reloaded at startup or when settings are applied.