Setting global variable in register_init Lua

Hi I am loading a JSON file in register_init() function of Lua. I want to set some global variables based on the JSON data read in register_init(). Please let me know, how I solve this.

Any non-local variable declared in the main scope of a lua script (outside of a function) is global, and may thus be accessed from any other function within the script.

global_string = ""
core.register_init(function()
  -- do something with json
  -- ...

  -- update global string variable
  global_string = "1"
end)

core.register_task(function()
  print(global_string) -- should print "1"
end)

does that help?