- Introduction
Plugin Creator Website (PCA) - Error Message
- Common Words in JSON
- List of Errors
Syntax Errors (1 listed)
TheoTown Errors (0 listed)
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---