How to debug JSON errors

Plugin specific problems will be solved here.

Moderator: Plugin Moderators

User avatar
Ølsken
Former Bearbear65
Reactions:
Posts: 4791
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta
Phone model: Samsung S10

Platform

Plugin Creator

How to debug JSON errors

#1

Post by Ølsken » Sat Jun 30, 2018 11:18

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.

TheoTown Errors

---WIP---
ImageJust my opinion

User avatar
The26
Townsman
Reactions:
Posts: 49
Joined: Wed May 23, 2018 22:18
Location: Bearlandia
Plugins: Show
Version: Beta
Phone model: BearPhone 9000

Platform

Re: Common plugin errors

#2

Post by The26 » Sat Jun 30, 2018 17:38

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

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

Platform

Plugin Creator

Re: Common plugin errors

#3

Post by CommanderABab » Sat Jun 30, 2018 17:39

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.
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:
Sat Jun 30, 2018 17:38
Very useful for beginner plugin creators. Great job! :)
Quotes for posperity sake. :)
777!777Currently using alpha 777. 777 What's new? :)
online maps!!
:)

Telegram - t.me/
🆎️🆎️🆎️🆎️Commander🆎️🆎️

User avatar
Between3Characters
Metropolitan
Reactions:
Posts: 127
Joined: Thu Oct 04, 2018 13:31
Plugins: Show
Version: Beta
Phone model: 082155558223 redmi4a

Platform

Re: Common plugin errors

#4

Post by Between3Characters » Thu Nov 22, 2018 1:42

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

User avatar
Lobby
Developer
Reactions:
Posts: 3384
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

Re: Common plugin errors

#5

Post by Lobby » 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":[{...}]
instead of

Code: Select all

"frames":{...}
...Have a nice stay

User avatar
Mrqwerty
Inhabitant of a Conurbation
Reactions:
Posts: 527
Joined: Sat Oct 06, 2018 21:48
Location: VER-MONT!
Plugins: Show
Version: Beta
Phone model: 2003 LG flip phone

Platform

Plugin Creator

Re: Common plugin errors

#6

Post by Mrqwerty » Sun Dec 02, 2018 0:29

Thx :json
WHAT IS THE DEAL WITH AIRPLANE FOOD :calc :bb :bq
My mediocre plugins

____________________________________________________________
...i like fish

User avatar
Ahmad Nur Aizat
TheoTown Veteran
Reactions:
Posts: 8187
Joined: Tue Oct 25, 2016 15:20
Location: Johor Bahru
Plugins: Show
Version: Beta
Phone model: Galaxy A50
Contact:

Platform

Plugin Creator

Re: Common plugin errors

#7

Post by Ahmad Nur Aizat » Wed Dec 05, 2018 3:03

How about the height limit error?

I can't sometimes balance the height required

User avatar
Between3Characters
Metropolitan
Reactions:
Posts: 127
Joined: Thu Oct 04, 2018 13:31
Plugins: Show
Version: Beta
Phone model: 082155558223 redmi4a

Platform

Re: Common plugin errors

#8

Post by Between3Characters » Wed Jan 16, 2019 13:15

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":[{...}]
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.
Moderators, dont delete our plugins please

User avatar
Ølsken
Former Bearbear65
Reactions:
Posts: 4791
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta
Phone model: Samsung S10

Platform

Plugin Creator

Re: How to debug JSON errors

#9

Post by Ølsken » Wed Nov 20, 2019 14:13

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

User avatar
JustAnyone
An important pickle
Reactions:
Posts: 2701
Joined: Sun Jul 23, 2017 12:45
Location: Easter Island
Plugins: Show
Phone model: Nokia 3310

Plugin Creator

Platform

Re: How to debug JSON errors

#10

Post by JustAnyone » Sat Nov 23, 2019 17:20

This will be reference page for PCA.

User avatar
Ølsken
Former Bearbear65
Reactions:
Posts: 4791
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta
Phone model: Samsung S10

Platform

Plugin Creator

Re: How to debug JSON errors

#11

Post by Ølsken » Sun Nov 24, 2019 8:39

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

User avatar
JustAnyone
An important pickle
Reactions:
Posts: 2701
Joined: Sun Jul 23, 2017 12:45
Location: Easter Island
Plugins: Show
Phone model: Nokia 3310

Plugin Creator

Platform

Re: How to debug JSON errors

#12

Post by JustAnyone » 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"?

User avatar
Ølsken
Former Bearbear65
Reactions:
Posts: 4791
Joined: Fri Feb 10, 2017 14:53
Plugins: Show
Version: Beta
Phone model: Samsung S10

Platform

Plugin Creator

Re: How to debug JSON errors

#13

Post by Ølsken » Sun Nov 24, 2019 11:55

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

Post Reply Previous topicNext topic

Return to “Problems”

Who is online

Users browsing this forum: No registered users and 2 guests