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

serializeJSON issues

Started by KingofGamesYami, 13 July 2016 - 10:05 PM
KingofGamesYami #1
Posted 14 July 2016 - 12:05 AM
I'm playing around with formatting books, and I've run into a bit of an obstacle: serializeJSON doesn't seem to work.

Here's what textutils.serializeJSON generates from my table:

{"display":{"Lore":["Store chests"]},"author":"KingofGamesYami","title":"Your Chests","pages":[""]}

Uing [font="monospace"}commands.give( "@p written_book 1 0", json ) does not work, and produces a book with an error message about an invalid data tag or some such.

However, using minecraft book editor, I generated this JSON:


{pages:[""],title:"Your Chests",author:"KingofGamesYami",display:{Lore:["Store Chests"]}}

Which in my mind is identical in function to the one above, but does work, when the one provided by serializeJSON does not.
Bomb Bloke #2
Posted 14 July 2016 - 01:52 AM
The former is JSON, the latter is not (and is instead dubbed a "datatag"). Those extra quotes matter, and which format is required varies depending on the Minecraft command you're specifically using.

See textutils.serializeJSON() for more info. Note the boolean parameter, and that if you passed in a table directly to commands.give() (instead of a pre-serialised string) it'd figure out the correct format for you automatically.