JSONedit: array generator (Lua scripting)
JSONedit 0.8 introduced array elements cloning allowing quickly extending array sizes. This was useful when having identical array elements was not a problem. Generated nodes could be manually edited later, but with large arrays it was tiring and error prone job (consider complex nested object that needs i.e. only one parameter unique but it takes half of the screen when its structure is expanded).
Second way of helping with array creation was CSV import function. It allowed using well-known and powerfull tools such as spreadsheet for data generation, but it was limited to only few conversion schemes from 2D CSV to nested (potentially lot more complicated) JSON structure.
JSONedit 0.9.5 makes use of integrated Lua interpreter to help with algorithmic array generation in few steps:
create "prototype" array element
- use RMB menu to open Array generator/Scripted cloning window;
selected array element will be automatically converted to quoted string with escaping
insert printf-style (Lua uses subset of C printf including %d, %s, %c, %f, %x, %X)
formatting markings into json string; "%d" below would be replaced with decimal number when executing
- add argument(s) to format function; math.random(10000) below would generate random number between 1 and 10000
that would be inserted instead of "%d"; multiple arguments (each one for each formatting mark) must
be separated by comma
- set required number of iterations (for i = 1, 10); each iteration by default generates single array element (single call to AddNodeAsSibling)
- execute script
- delete "prototype" element if not needed anymore
While example above is very simple (identical effect could be achieved with CSV import function in fact) this method of array generation offers great flexibility. For simple tasks like this one I believe that no previous Lua knowledge is needed (if you are familiar with printf formatting), more complicated tasks may require some Lua documentation browsing. You may also use same concept with your own favorite programming language.