10/07/19, 02:07 PM | #1 |
|
JSON to Lua
Anyone have any ideas how to convert a JSON script to a Lua table so it can be read by add-ons?
Here's an example of the JSON: Code:
{"numRecords":1,"quest":[{"id":"2345","logId":"144998164","locationId":"20246462","name":"Depths of Madness","level":"50","type":"0","repeatType":"0","displayType":"0","backgroundText":"I found a lost member of the Queen's entourage near the entrance to a hidden Vale. She told me that her fellow entourage members have been taken. A mad mage apparently holds them in the Vale.","objective":"Glister Vale","poiIndex":"4","goalText":"Talk to Eminelya","confirmText":"","declineText":"","endDialogText":"Sanessalmo? Now that name I remember. Used to be a member of the Queen's inner circle! \n\nYou have my deepest gratitude for your service today. I'll be sure the Queen learns of your bravery.","endBackgroundText":"I found a lost member of the Queen's entourage near the entrance to a hidden Vale. She told me that her fellow entourage members have been taken. A mad mage apparently holds them in the Vale.","endJournalText":"I returned to Eminelya's side. I should speak to her one last time.","isShareable":"1","numTools":"1","hasTimer":"0","timerCaption":"Depths of Madness","timerDuration":"0","numSteps":"1","numRewards":"-1","count":"19","zone":"Auridon","internalId":"4272"}]} Thanks! |
10/07/19, 03:26 PM | #2 |
https://github.com/rxi/json.lua
Use Json.decode in a normal lua environment (e.g. windows cmd line) to get the data and store it in a txt file e.g., rename it to .lua for your SavedVariables or a lua file you include in your addon afterwards and load them into your addon. |
|
10/08/19, 04:54 AM | #3 |
Don't think that's enough. You'd still need to serialize it into Lua code so the game can load it.
As I see it you have two different approaches you can take. Either you convert it before the game loads it, or after. In the first case you have to use some library that can read the JSON data and another library to serialize it into Lua code that can be read by the game. Reading the JSON data is the smallest issue here as it is well supported in plenty of languages. The problem is how to generate the Lua code. There doesn't seem to be any out of the box solutions, but then again it's not really hard to do it yourself with a few lines of code. It won't even matter which language you use for that. JS, Lua, Java - anything is fine. If you want to avoid that problem altogether you could look for a pure Lua implementation of a JSON library, write a small addon that takes JSON in a text field, put it into a saved variable and let the game serialize it for you. The other way would be to simply dump the JSON string into a Lua string and then deserialize it at runtime with said pure Lua implementation of a JSON library. That may be a bit simpler in terms of complexity, but may cause performance issues depending on how much data you want to load that way. |
|
10/08/19, 05:37 AM | #4 |
Wouldn't maybe this do the lua stuff for you (using the json lua library mentioned above):
Lua Code:
Not sure though if one can send this to a file from lua Or maybe the script taken from this link (https://gist.github.com/tylerneylon/...f316be525b30ab) helps: Put it in a file called (for example) json.lua, and include it in your project with something like json = require "json" Lua Code:
Last edited by Baertram : 10/08/19 at 05:39 AM. |
|
ESOUI » Developer Discussions » Lua/XML Help » JSON to Lua |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|