How to debug JSON errors

Plugin specific problems will be solved here.

Moderator: Plugin Moderators

User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

How to debug JSON errors

#1

Post by Bearbear76 »

Contents
  1. Introduction
    Plugin Creator Website (PCA)
  2. Error Message
  3. Common Words in JSON
  4. List of Errors
    Syntax Errors (1 listed)
    TheoTown Errors (0 listed)
Introduction

Any plug-in creator will bump into JSON errors. It is usually not that hard to debug once you get used to it.
JSON errors are pretty calm & easy to fix compared to Lua (A scripting language used for plug-ins),
for such errors I would also suggest using third-party validators to debug your JSON such as: Jsonlint.
However, sometimes you can get a nasty error which could seem impossible to fix but do not worry this thread will teach
the basics of debugging a JSON file
and also list some solutions to known errors.


Plugin Creator Website (PCW)

Plugin Creator Website or PCW is a community developed tool by JustAnyone.
PCA is a well developed tool that allows people who are not familiar with JSON to easily create JSON while avoiding syntax errors.
If you are new to JSON, I would recommend using it. People who would like to make more complicated JSON using functions should refrain from using it as functions will not be supported in the near future.

Error Message

Whenever you run a JSON containing an error within TheoTown displays an error message at the beginning; during initialisation.
This error message contains useful information such as the directory or location in where the error occurred and the type of error that occurred.
Now, let's look at an error message that contains, quite frankly, the most common error in JSON.


In /.../TheoTown/plugins/MyPlugin/plugin.json:

util.json.JSONException: Unterminated object at character x.


The first line indicates where the error occurred. In this case it would be in a JSON called 'plugin.json' inside a folder called 'MyPlugin'.
Note: /.../ is where the directory of the TheoTown folder. This varies between devices such as Android or Windows etc...


In /.../TheoTown/plugins/MyPlugin/plugin.json:

The second like specifies which error you got at what character. Although I would prefer it to show at which line the error occurred rather than character for convenience's sake, but we have to work with what is given.
With characters you can somewhat guess where the error occurred especially in long JSON code, but that is a skill that you can only develop with practice.


util.json.JSONException: Unterminated object at character x.

Now that you have learnt how to read error messages given by TheoTown you can start editing JSON files to fix errors!

Common Words in JSON

These are some words you may want to know when working with JSON.

keys: Keys are basically tags, such as "id" or "type".

[{
"id":"$park01",
"type":"park"
}]


values: Values are the information inside keys. keys and values are always in pairs in JSON.

[{
"id":"$park01",
"type":"park"
}]


Objects: There are two types of objects in JSON, main objects (highlighted in yellow), and key-value pair objects (highlighted in blue).

[{
"id":"$park01",
"type":"park"

}]



Arrays: Arrays are boxes that can contain objects and also values.

[{
"id":"$park01",
"type:"park"
}]


List of Errors

This is where most of the known errors which occurred in the past will be documented.

Syntax Errors

Syntax errors are simply grammatical errors. Think of it as if you wrote 'I have many dog' in English, JSON follows are structure of rules that must be followed and if you make grammatical mistakes it will throw out an error. However, JSON syntax isn't that convoluted so it is relatively easy to write.

util.json.JSONException: Unterminated object at character x.

Solution: Object wasn't terminated properly. Usually missing a comma or curly bracket at the end of an object at character x.

util.json.JSONException: Expected ':' after type at character x.

Solution: Missing a : after key at character x.

util.json.JSONException: Expected literal value at character x.

Solution: The opposite of unterminated object. Has an excess comma at character x.
General tip would be to not put a comma behind a } such as:


[{
...
"frames":[{"bmp":"example.png",}],
}
]

TheoTown Errors

TheoTown errors are not syntax errors, but errors caused by TheoTown specific JSON rules in order to load a plugin properly. Therefore these errors are not detectable by 3rd party validators such as Jsonlint and only by TheoTown.

java.lang.illegal.ArgumentException: May not find a loader for type not defined.

Solution: Probably a typo of the type key, or type was not defined (missing type).

java.lang.illegal.ArgumentException: May not find a loader for type (value).

Solution: Probably a typo of the type value, or the entered value doesn't exist.

java.lang.illegalStateException: When loading "null": No value for id.

Solution: Probably a typo of the id key, or id was not defined (missing id).

java.lang.illegalStateException: Please specify width and height attributes. They have to be equal and >= 1.

Solution: General problem with width or height object. Width and height must be equal and greater or equal to 1. Could also be a typo.
The following will give you an error:


"with":1, <-- typo of width
"height":0, <-- less than 1 + not equal values

---WIP---
User avatar
The26
Inhabitant of a Megacity
Reactions:
Posts: 181
Joined: 23 May 2018, 22:18
Location: Lithuania
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Common plugin errors

#2

Post by The26 »

Very useful for beginner plugin creators. Great job! :)
User avatar
CommanderABab
AB
Reactions:
Posts: 11080
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Common plugin errors

#3

Post by CommanderABab »

Bearbear65 wrote: 30 Jun 2018, 11:18 Hello!
Here I will list some common plugin errors.
I wrote the solution and the definition of the error message you get when you open Theotown.
This was based on the majority of the plugin errors sent by people

You can help expand this list by writing an error with the solution! :)

Code: Select all

org.json.JSONException: Unterminated object at character x.
Definition: This means that the plugin wasn't terminated in a specific line. ( doesn't have a comma at the end of a line)
Solution: Add a comma to the line which doesn't include a comma.

Code: Select all

org.json.JSONException: Expected literal value at character x.
Definition: Simply, the opposite of "Unterminated object". Means that you have put a comma in where you didn't have to.
Solution: Remove the extra comma that you added. ( Remember that commas don't precede }] )

Code: Select all

java.lang.IllegalArgumentException: Id x is already in use. Use another id or add "override":true to your plugin.
Definition: Means that the given Id was already in use, in other words a plugin with the same id exists in your plugin folder or Theotown.
Solution: There are many causes for this, e.g. Downloaded a plugin twice, put both the folder and zip inside the plugin folder etc...
So, the easiest way to solve this is by adding "override":true, or changing the id.
If you're trying to replace a in-game building then you must add "override":true, for it to be overridden.

Code: Select all

java.lang.IllegalArgumentException: Cannot fit bmp x.png of size y into world texture (maybe too many plugins?)
Definition: As it says, it means that you have unfortunately reached the limit of the world texture. (space for plugin texture)
Solution: Clean your texture space by deleting unnecessary plugins, or give up on the plugin you wanted to add.

Code: Select all

java.lang.IllegalArgumentException: No category x could be found
Definition: It means that it could not have found the category that is required for the plugin.
Solution: Check if you have downloaded the category. Some plugin creators include the download for the category on the download page, some are
Already in the plugin. In this case it's usually because you have not downloaded the separate category for the plugin. Check the download page once more to see if you can find it.


The best thing to do is not to edit the file unnecessarily! :json
The26 wrote: 30 Jun 2018, 17:38 Very useful for beginner plugin creators. Great job! :)
Quotes for posperity sake. :)
User avatar
Between3Characters
Metropolitan
Reactions:
Posts: 123
Joined: 04 Oct 2018, 13:31
Plugins: Showcase Store
Version: Beta

Platform

Re: Common plugin errors

#4

Post by Between3Characters »

What about the jsonobject cannot be converted to jsonarray? I got that problem, but then i check syntax and it says valid.... Or did i miss something? For example, image? Its a category though..
User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: Common plugin errors

#5

Post by Lobby »

You probably used {} where [] is needed. E.g. you might have forgot to put [] around a frame:

Code: Select all

"frames":[{...}]
instead of

Code: Select all

"frames":{...}
User avatar
Mrqwerty
Inhabitant of a Megalopolis
Reactions:
Posts: 579
Joined: 06 Oct 2018, 21:48
Location: Vermont, United States
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Common plugin errors

#6

Post by Mrqwerty »

Thx :json
User avatar
Ahmad Nur Aizat
TheoTown Veteran
Reactions:
Posts: 8260
Joined: 25 Oct 2016, 15:20
Location: Johor Bahru
Plugins: Showcase Store
Version: Beta
Contact:

Plugin Creator

Platform

Re: Common plugin errors

#7

Post by Ahmad Nur Aizat »

How about the height limit error?

I can't sometimes balance the height required
User avatar
Between3Characters
Metropolitan
Reactions:
Posts: 123
Joined: 04 Oct 2018, 13:31
Plugins: Showcase Store
Version: Beta

Platform

Re: Common plugin errors

#8

Post by Between3Characters »

Lobby wrote: 22 Nov 2018, 01:51 You probably used {} where [] is needed. E.g. you might have forgot to put [] around a frame:

Code: Select all

"frames":[{...}]
instead of

Code: Select all

"frames":{...}
I am on the way to make a new park category. I still got an error, even if i already put that on frames. Whats going on? Check the last post in this forum.
User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to debug JSON errors

#9

Post by Bearbear76 »

Currently working on a new version. Sorry if you are trying to use this post for guidance.
User avatar
JustAnyone
Developer
Reactions:
Posts: 3470
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: How to debug JSON errors

#10

Post by JustAnyone »

This will be reference page for PCA.
User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to debug JSON errors

#11

Post by Bearbear76 »

JustAnyone wrote: 23 Nov 2019, 17:20 This will be reference page for PCA.
added PCA document
User avatar
JustAnyone
Developer
Reactions:
Posts: 3470
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: How to debug JSON errors

#12

Post by JustAnyone »

well developed - good joke, regardless what do you mean by "functions will not be supported in the near future"?
User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to debug JSON errors

#13

Post by Bearbear76 »

JustAnyone wrote: 24 Nov 2019, 11:44 well developed - good joke, regardless what do you mean by "functions will not be supported in the near future"?
you said PCW won't support fun but just in case I made it 'not in the near future'. maybe my wording was a bit off
User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to debug JSON errors

#14

Post by Bearbear76 »

I got to clean this post up :lol:
User avatar
1Code
Inhabitant of a Megacity
Reactions:
Posts: 302
Joined: 30 Jan 2020, 16:56
Location: https://bit.ly/3P5dhnT
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to debug JSON errors

#15

Post by 1Code »

Last edited by 1Code on 26 Jun 2021, 11:33, edited 3 times in total.
User avatar
Bearbear76
Former Bearbear65
Reactions:
Posts: 5730
Joined: 10 Feb 2017, 14:53
Location: L2 cache
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to debug JSON errors

#16

Post by Bearbear76 »

Nice video looks like a weta (the bug). :)
Bearbear76 wrote: 10 Feb 2021, 11:44 I got to clean this post up :lol:
This post is pretty messy and I want to fix it but I don't have much time... :(
User avatar
1Code
Inhabitant of a Megacity
Reactions:
Posts: 302
Joined: 30 Jan 2020, 16:56
Location: https://bit.ly/3P5dhnT
Plugins: Showcase Store

Plugin Creator

Platform

Re: How to debug JSON errors

#17

Post by 1Code »

20220207_192824.png
User avatar
Srbio
Villager
Reactions:
Posts: 12
Joined: 22 Apr 2022, 16:39

Re: How to debug JSON errors

#18

Post by Srbio »

I have a problem I have made a plugin with night animations but
When I load the game it says that the id:Night Animation couldn't find an animation draft what should I do i have done everything right
User avatar
CommanderABab
AB
Reactions:
Posts: 11080
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: How to debug JSON errors

#19

Post by CommanderABab »

May you share the code?
User avatar
Srbio
Villager
Reactions:
Posts: 12
Joined: 22 Apr 2022, 16:39

Re: How to debug JSON errors

#20

Post by Srbio »

Plugin Error (T_T)

Unfortunately an error occurred while loading your plugins. Update or remove the plugin mentioned below in order to start Theo Town again. If you're a plugin creator you may have a deep look into your code (@.@).

A side note: You should add a plugin.manifest file to your plugin so that it can be identified when used by others.

In plugins..... my file ......json:

java.lang.IllegalStateException: When loading "...Also some file": Could not find an animation draft of id Night Animation!

Cancel
Last edited by Srbio on 22 Sep 2022, 13:15, edited 1 time in total.
Post Reply Previous topicNext topic

Return to “Problems”