This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Luca_S's profile picture

textutils.unserialiseJSON()

Started by Luca_S, 12 April 2016 - 05:56 PM
Luca_S #1
Posted 12 April 2016 - 07:56 PM
Pretty self explanatory, converts JSON to a lua table, ik that there are already some APIs for that on the forums, but we have textutils.serialiseJSON() so that would make sense.
Anavrins #2
Posted 12 April 2016 - 08:08 PM
I think the original use for serializeJSON was to have an easy way to interact with MC command, via command computers.
With this purpose, there's not much use for unserialiaztion.

Though it would be nice to have so we can interact with json based web apis.
Luca_S #3
Posted 12 April 2016 - 08:19 PM
-snip-
Though it would be nice to have so we can interact with json based web apis.

That would be the main purpose
wilcomega #4
Posted 13 April 2016 - 04:56 PM
+1
Wergat #5
Posted 22 April 2016 - 01:33 PM
I think the original use for serializeJSON was to have an easy way to interact with MC command, via command computers.
With this purpose, there's not much use for unserialiaztion.
There is still, sometimes you want to parse the output of command-blocks to useable data.

To clarify:
JSON is only used for /tellraw, while other commands use a slightly different version of JSON (Why add this parser if you have to change it, still?)
I made a function to properly unserialize it (Here), and BombBloke used the build-in function for JSON here, but changed it a little afterwards to make it work.

In general, i would want a function to (un-)serialize both the "lenient" version of JSON and the normal JSON via build-in API's
Bomb Bloke #6
Posted 22 April 2016 - 02:31 PM
To clarify, I didn't change anything - Dan did, a few months after you wrote your serialisation function. textutils.serialiseJSON() now accepts a parameter allowing you to toggle its behaviour between outputting proper JSON or whatever it is Minecraft uses when it's not using that. He also tweaked all the relevant functions in the commands API to automatically apply that toggle when appropriate; you should see this fixed behaviour in any of the Minecraft 1.8 builds of ComputerCraft.

Remember, serialisation converts an object into a string. The "unserialise" function that is in my banner editor goes the other way, turning a JSON string into a Lua table (well, it should at least work for all the strings that script should encounter, anyway).
dan200 #7
Posted 01 May 2016 - 02:04 AM
Parsing JSON isn't nearly as easy as generating it. Who wants to write a compact JSON parser for me?
KingofGamesYami #8
Posted 01 May 2016 - 02:17 AM
It's been done.
Luca_S #9
Posted 01 May 2016 - 08:22 PM
Parsing JSON isn't nearly as easy as generating it. Who wants to write a compact JSON parser for me?

Ik that it would be a bit of a code block and I know there are APIs for it, but it would just make sense if you had textutils.unserialiseJSON()