Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'EOF' #238

Closed
JPVenson opened this issue Nov 24, 2015 · 16 comments
Closed

Comments

@JPVenson
Copy link

hey,

I tried to set the JSON to the Editor and got the error you can see in the header:

Error: Parse error on line 1:

^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'EOF'

The string i tried to push is:

[{"test":"test"}]

Both methods set, setText produces this error
any help?

@josdejong
Copy link
Owner

I think the code you try to load contains some weird character, the error you print there says that it sees an EOF (end of file) character.

@JPVenson
Copy link
Author

Yea but why? I cannot find the Problem nor a Sollution for it.

i am using

and this seems like the latest version

@josdejong
Copy link
Owner

I see I had a typo in my previous comment, ment to say I expect there is an invalid character in the string you try to load.

@JPVenson
Copy link
Author

Well I tried to load a Constant string:

        var editor: JSONEditor;
        var JsonEditOptions = {
            "mode": "code",
            "modes": [
                "tree",
                "form",
                "code",
                "text"
            ],
            "history": false,            
        }
        editor = new JSONEditor(document.getElementById("json-editor"), JsonEditOptions);
        editor.set("[{\"test\":\"test\"}]");

and not even that is working. It throws the exception at the set function.

@josdejong
Copy link
Owner

ah, you pass a string instead of a JSON object. You can do either one of the following:

editor.setText("[{\"test\":\"test\"}]");

var json = JSON.parse("[{\"test\":\"test\"}]");
editor.set(json);

here an example:

http://jsbin.com/gekohi/edit?html,output

@josdejong
Copy link
Owner

I still don't get it exactly, your code should still work and not throw an error: just load your text as a string containing this JSON.

@JPVenson
Copy link
Author

I did so

editor.set(angular.fromJson("[{"test":"test"}]"));

still throws the error

capture

nor

capture2

@JPVenson
Copy link
Author

I even tried to switch from my Local version to the CDN one. Same error

@JPVenson
Copy link
Author

Ok i found, somehow the error. Its the Options object. After calling the Constructor without it, it shows property. This is no solution for me because i must be aware of the change event, but now it shows the Editor.

Edit:
Ok its seems like an error with the Mode option:

var JsonEditOptions = {
change: () => {
if (editor != null)
this.SelectedItem.Content = editor.get();
}
}

is working fine for me.

edit 2:
Ok no problem with Mode, but with modes:
modes

"modes": [
"tree",
"form",
"code",
//"text"
],
is ok but with text enabled it's not

@josdejong
Copy link
Owner

Can you create a jsbin demonstrating the issue? I don't know how to reproduce it.

@JPVenson
Copy link
Author

The exact code:

http://jsbin.com/yobeqagujo/1/edit?html,output

@josdejong
Copy link
Owner

I found the issue: in your change listener you do an editor.get():

change: function () {
  if (editor != null) {
    var contents = editor.get(); // ooops, editor.get() can throw an Exception
  }
}

This method editor.get() fails when the editor contains invalid JSON, which can be the case when you're in mode code or text. So to solve this, you could either use editor.getText() instead, or put a try/catch around editor.get() and handle this case somehow.

@JPVenson
Copy link
Author

No thats not the problem, try comment it out and it still not working.

http://jsbin.com/pimivufibu/1/edit?html,output

After its works i found that problem and fixed it with:

this.SelectedItem.Content = angular.fromJson(editor.get());

this was right after my change to the working code:
https://jsbin.com/xedezofoko/2/edit?html,output

@josdejong
Copy link
Owner

No thats not the problem, try comment it out and it still not working.

?

your jsbin works indeed fine without the change listener (except for a ReferenceError as angular.fromJson is not defined).

I updated my jsbin, it throws exactly your original exception: http://jsbin.com/gekohi/edit?html,output. When you comment the change listener out, the problem is fixed.

@josdejong
Copy link
Owner

In mode code and text, you will have to give the DIV container where you put the JSONEditor a height.

@JPVenson
Copy link
Author

Jes i saw that just a sec ago ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants