Results 1 to 4 of 4

Thread: Allow JSON file read/load

  1. #1
    Basic Member
    Join Date
    Dec 2016
    Posts
    618

    Question Allow JSON file read/load

    Is it possible to load a pure JSON file through the dofile(), require() or even by leveraging the provided dkjson.lua module?

    In my web-server bot implementation I'm trying to organize my code better and thus created pure JSON file for various data that I want re-used both on the bot-running instance as well as the back-end server.

    For example, I created a web_config.json file that is:
    Code:
    {
        "IP_ADDR" = "127.0.0.1",
        "IP_PORT" = 2222
    }
    both, require() and dofile() refuse to work (since they assume a ".lua" extension); and even changing the filename to .lua extension still fails as at minimum a "return" would need to be present.

    dkjson's decode() requires a JSON string, not a JSON file and I did not see a function for reading a file.

    Any chance of allowing JSON file loading in the API? This would be hugely beneficial for re-use of data-type and object definitions between the two systems. As in the above example where I could reuse the same JSON key,value pairs to instruct the CreateHTTPRequest() as well as to spawn my web-server backed.

  2. #2
    Basic Member
    Join Date
    Dec 2016
    Posts
    53
    why not
    web_config.lua:

    return encoded json string
    just need a tiny script to convert *.json to *.lua.

  3. #3
    Basic Member
    Join Date
    Dec 2016
    Posts
    618
    Quote Originally Posted by lenlrx View Post
    why not
    web_config.lua:
    just need a tiny script to convert *.json to *.lua.
    Sure it is trivial, just add a return on the Lua side and change extension. Then on the Python/C#/C++/whatever side just strip the return off and interpret as JSON.

    But, because it is so trivial it should be 10 min of @ChrisC time to write a JSON loader API (just slap a return before file read of a .json) and return table. We do not have access to file read in the Lua, but the API could provide it.

    This is just a small QoL API request; not a blocker

  4. #4
    Basic Member axetion's Avatar
    Join Date
    Jan 2017
    Posts
    35
    This would be real nice, currently I'm having to emit Lua code for my data which is nasty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •