## How to debug JSON errors

Plugin specific problems will be solved here.

Moderator: Plugin Moderators

Bearbear76
Former Bearbear65
Reactions:
Posts: 5299
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

### How to debug JSON errors

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.

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---
Just my opinion

The26
Townsman
Reactions:
Posts: 53
Joined: Wed May 23, 2018 22:18
Location: Bearlandia
Plugins: Show
Version: Beta

### Re: Common plugin errors

Very useful for beginner plugin creators. Great job!
Presents are amazing things, and bears are amazing animals.

CommanderABab
AB
Reactions:
Posts: 8651
Joined: Tue Jun 07, 2016 21:12
Plugins: Show
Version: Beta

### Re: Common plugin errors

Bearbear65 wrote:
Sat Jun 30, 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.
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!
The26 wrote:
Sat Jun 30, 2018 17:38
Very useful for beginner plugin creators. Great job!
Quotes for posperity sake.

Between3Characters
Metropolitan
Reactions:
Posts: 123
Joined: Thu Oct 04, 2018 13:31
Plugins: Show
Version: Beta

### Re: Common plugin errors

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..
Moderators, dont delete our plugins please

Lobby
Developer
Reactions:
Posts: 3538
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta

### Re: Common plugin errors

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

Code: Select all

"frames":[{...}]

Code: Select all

"frames":{...}
=^._.^= ∫

Mrqwerty
Inhabitant of a Megalopolis
Reactions:
Posts: 574
Joined: Sat Oct 06, 2018 21:48
Location: Barre, Vermont, United States
Plugins: Show
Version: Beta

### Re: Common plugin errors

Thx
WHAT IS THE DEAL WITH AIRPLANE FOOD

____________________________________________________________
...

TheoTown Veteran
Reactions:
Posts: 8243
Joined: Tue Oct 25, 2016 15:20
Location: Johor Bahru
Plugins: Show
Version: Beta
Contact:

### Re: Common plugin errors

How about the height limit error?

I can't sometimes balance the height required

Between3Characters
Metropolitan
Reactions:
Posts: 123
Joined: Thu Oct 04, 2018 13:31
Plugins: Show
Version: Beta

### Re: Common plugin errors

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

Code: Select all

"frames":[{...}]

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.
Moderators, dont delete our plugins please

Bearbear76
Former Bearbear65
Reactions:
Posts: 5299
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

### Re: How to debug JSON errors

Currently working on a new version. Sorry if you are trying to use this post for guidance.
Just my opinion

Online
JustAnyone
enjenir
Reactions:
Posts: 2925
Joined: Sun Jul 23, 2017 12:45
Location: Easter Island
Plugins: Show

### Re: How to debug JSON errors

This will be reference page for PCA.

Bearbear76
Former Bearbear65
Reactions:
Posts: 5299
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

### Re: How to debug JSON errors

JustAnyone wrote:
Sat Nov 23, 2019 17:20
This will be reference page for PCA.
Just my opinion

Online
JustAnyone
enjenir
Reactions:
Posts: 2925
Joined: Sun Jul 23, 2017 12:45
Location: Easter Island
Plugins: Show

### Re: How to debug JSON errors

well developed - good joke, regardless what do you mean by "functions will not be supported in the near future"?

Bearbear76
Former Bearbear65
Reactions:
Posts: 5299
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta

### Re: How to debug JSON errors

JustAnyone wrote:
Sun Nov 24, 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
Just my opinion