19

Often, when making a command block contraption, you need to set an entity's data tag. These tags can sometimes be very long, with many layers of nested curly and square brackets. For example, this is the command to summon a villager with a single custom trade:

/summon Villager ~ ~ ~ {Profession:3,Career:2,Offers:{Recipes:[{buy:{id:minecraft:diamond,Count:6b}},sell:{id:minecraft:diamond_hoe,tag:{ench:[{id:16s,lvl:10s}]}]}}

The single-line command block interface of Minecraft makes it incredibly difficult to find and fix errors, especially when it comes to mismatched brackets. In fact, for illustration purposes, I put an error in the above command.

What techniques can I use to find and fix unbalanced square or curly brackets when writing long and complicated data tags?

9
  • I'm surprised there isn't an automated tool for at least checking the structure of data tags. Perhaps this should be rectified.
    – MBraedley
    Commented May 15, 2016 at 15:59
  • @MBraedley yeah, I'm a bit surprised myself. Minecraft's lenient JSON parsing makes most regular JSON checkers complain.
    – MrLemon
    Commented May 15, 2016 at 16:06
  • Just a question, since this is clearly for all the "what's wrong with my command?" questions, should the question title be re-worded to match something a bit more google-search relative?
    – Ben
    Commented May 15, 2016 at 22:46
  • For reference, I provided basically this exact solution on this question here: gaming.stackexchange.com/questions/207989/…
    – Robotnik
    Commented May 16, 2016 at 2:07
  • ^Heh, just realised @MrLemon - you even commented on it :)
    – Robotnik
    Commented May 16, 2016 at 3:46

2 Answers 2

32
+100

The easiest way to find mismatched braces is to expand the command into a multi-line format with properly indented lines. This makes it easier to find errors and subsequently fix them.

A nifty little tool to automatically format your data tags can be found at http://jsonviewer.stack.hu/. Using the Format and Remove White Space buttons, you can expand or collapse your command, respectively. Using the sample data tag given in the questions, we can turn this

{Profession:3,Career:2,Offers:{Recipes:[{buy:{id:minecraft:diamond,Count:6b}},sell:{id:minecraft:diamond_hoe,tag:{ench:[{id:16s,lvl:10s}]}]}}

into this

{
  Profession: 3,
  Career: 2,
  Offers: {
    Recipes: [
      {
        buy: {
          id: minecraft: diamond,
          Count: 6b
        }
      },
      sell: {
        id: minecraft: diamond_hoe,
        tag: {
          ench: [
            {
              id: 16s,
              lvl: 10s
            }
          ]
        }
      ]
    }
  }

Now all that is left is compare the opening and closing brackets at each indentation level. You can see that there is no closing bracket at the last indentation level, the last bracket is indented once, showing us that there is a closing bracket missing on some level.

If you check all the tags starting at the top, you can see that there's a problem with the sell tag: There's a closing square bracket instead of a curly bracket on that indentation level. To make this even more visible, we can copy-paste our data tag into an advanced text editor like Notepad++, which highlights matching brackets for us:

Have the missing curly bracket problem:

notepad++ view

Here it is immediately apparent that a closing curly bracket is needed for the sell tag.

Without the missing bracket:

enter image description here

0

To add a bit of info: I don't think that any formatting is needed, unless you have a 1000+ character command.
For begining Minecraft "programmers" I would recommend copying the command to Notepar/Gedit, finding the most indent brackets and deleting their content, then deleting the contents of the brackets "under" those and repeat untill they find a missing/wrongly placed pair.
For more advanced users I'd recommend doing it as I do: just thinking out the bracket pairs. By this way, I (and anyone else can) found the mistake in the example command in like 10 seconds without seeing the existinbg answer.

Hope was helpfull!

Not the answer you're looking for? Browse other questions tagged or ask your own question.