JSON en/decode for a simple configuration file

Extending or modifying the GP system itself (advanced!)

Moderator: MSandro

Post Reply
Posts: 162
Joined: Jul 26th, '17, 21:12

JSON en/decode for a simple configuration file

Post by MSandro » May 28th, '18, 13:04

This is a very simple project / extension to understand how to manage a config file with JSON en/decode and global variables. You don't have to use global variables, I've used it because it makes the management easier.
I hope you can do something with it. There is currently not fallback with default values, In the "SaveSettings" block you only have to set the names of your global variables which you want to read and write out to the file.

You can also load your settings on the startup of GP. This is my startup.gp:

Code: Select all

to startup {
  setGlobal 'vectorTrails' false
  openProjectEditor true true
You only need to execute "loadSettings" which I've stored in a "settings.gp" in the lib folder

If you want to output formated json file, you have to use

Code: Select all

(stringify (initialize (new 'JSONWriter')) dict true)
instead of (jsonStringify dict) because you need the formatFlag, it is the last argument in the code line.
(6.98 KiB) Downloaded 944 times

Post Reply