mojira.dev
REALMS-3007

JSON validator too strict- doesn't allow json string type ( ' ) or returns within strings

The json validator for realms is too strict and doesn't allow nbt fields within strings.

These forms of loot tables will work in single player and on servers, but realms will refuse to load them:

 

{
    "type": "minecraft:loot",
    "pools":
      [{   
        "rolls": 1,
        "entries": [{
          "type": "minecraft:item",
          "name": "minecraft:written_book",
          "functions": [{
            "function": "minecraft:set_nbt",
            "tag": "{     
              title:\"Book title\", 
              author:\"Some name\",
              pages:[   
                \'\"text\"\'
              ]
            }"
          }]
        }]
      }]
    }

 

{
    "type": "minecraft:loot",
    "pools":
      [{   
        "rolls": 1,
        "entries": [{
          "type": "minecraft:item",
          "name": "minecraft:written_book",
          "functions": [{
            "function": "minecraft:set_nbt",
            "tag": "{ title:\"Book title\", author:\"Some name\", pages:[ \'\"text\"\' ] }"
          }]
        }]
      }]
    }

Comments 2

It's true that Realms is more strict than the game, but according to the ECMA-404 spec, newlines, carriage returns, and tab characters are illegal within JSON strings:

Insignificant whitespace is allowed before or after any token. Whitespace is any sequence of one or more of
the following code points: character tabulation (U+0009), line feed (U+000A), carriage return (U+000D), and
space (U+0020). Whitespace is not allowed within any token, except that space is allowed in strings.

In fact, even in JavaScript, which is much less strict than JSON, those characters are not allowed (per ECMA-262):

All characters may appear literally in a string literal except for the closing quote character, backslash, carriage return, line separator, paragraph separator, and line feed. Any character may appear in the form of an escape sequence.

Finally, single quotation marks have no importance in JSON syntax, so they should not be used in JSON to mark strings (incl. the nested JSON inside the tag definition).

These example lines:
 

"tag": "{     
              title:\"Book title\", 
              author:\"Some name\",
              pages:[   
                \'\"text\"\'
              ]
            }"

... should become:

"tag": "{     \n              title:\"Book title\", \n              author:\"Some name\",\n              pages:[   \n                \"\\\"text\\\"\"\n              ]\n            }"

or you might as well compress it, since it's hardly readable anyway:

"tag": "{title:\"Book title\",author:\"Some name\",pages:[\"\\\"text\\\"\"]}"

I agree there is a bug here in that the parse & validation are inconsistent, but I don't necessarily agree that Realms is wrong.

Here is a JavaScript snippet I tested in Chrome that should convert your loot table(s) to be compliant with Realms and then will copy it to your clipboard:

var loot = {
    "type": "minecraft:loot",
    "pools":
      [{   
        "rolls": 1,
        "entries": [{
          "type": "minecraft:item",
          "name": "minecraft:written_book",
          "functions": [{
            "function": "minecraft:set_nbt",
            "tag": "{                   title:\"Book title\",               author:\"Some name\",              pages:[                   '\"text\"'              ]            }"
          }]
        }]
      }]
    };

for (pool of loot.pools) { if (pool.entries) for (entry of pool.entries) { if (entry.functions) for (func of entry.functions) { if (func['function'] === 'minecraft:set_nbt') func.tag = JSON.stringify(eval(`(${func.tag})`)); } } }
copy(loot);

(Replace the loot object literal with the contents of your loot table file.)

Thank you for your report!

Minecraft Realms for Java Edition has received a lot of updates and fixes over the last two years, so this issue has probably already been fixed in the meantime (e.g. because it was a temporary outage or an issue with the base game).

Since this bug report has not been updated since at least two years, please let us know if this is still an issue in current versions of Minecraft and update the bug report if applicable. If this is no longer an issue, please let us know as well. Thanks!

This issue is being temporarily resolved as Awaiting Response. Once the requested information has been delivered, the report will be reopened automatically.

Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki – 📖 FAQs

MukiTanuki

(Unassigned)

Unconfirmed

Java

JSON, Json_file, data-pack, json, json-text, json_string

Retrieved