Search code examples
jsonadobe-brackets

JSON for newbs - for Adobe Brackets functionality


I am completely unfamiliar with JSON. I don't use it on a regular basis so I'm just looking for a quick fix, but as a programmer I'd love some basic understanding also.

I'm using Brackets to edit some content for work, and auto-complete is driving me CRAZY. I hate you auto-complete, I hate you so much. I found a snippet of code at https://github.com/talmand/Brackets-Disable-AutoClose-Tags which is supposed to negate auto-complete when opening a new tag. It does not totally shut off auto-complete - it still tries to complete your closing tag once begun. Intended to be useful but I find it intensely irritating.

I inserted the code into the Preferences File, and in the statement, it seems pretty obvious that all I should need to do is change whenClosing to false, but when I do it, then close and reopen the program so it'll take effect, it tells me that my Preferences File contains invalid JSON. All I changed was the value true to false for whenClosing. I used JSONlint to try and see what's wrong, but JSON is not a familiar language for me. Code is included below.

What am I doing wrong?

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This is the unaltered code that I copied into the file:

"closeTags": { "whenOpening": false, "whenClosing": true, "indentTags": [] }

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

And this is the total block that my Preferences File contains, with my edit:

{
    "closeBrackets": false,
    "debug.showErrorsInStatusBar": true
}

"closeTags": { "whenOpening": false, "whenClosing": false, "indentTags": [] }

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

And this is what JSONlint said:

Parse error on line 4:
...InStatusBar": true}"closeTags": {    "
----------------------^
Expecting 'EOF', '}', ',', ']'

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@Shaunak that makes sense! I added the comma though, and got this:

After adding the needed comma


Solution

  • You need a comma after closing bracket.

    {
        "closeBrackets": false,
        "debug.showErrorsInStatusBar": true
    }, <<<<<<<<< ----- You need a comma here :) 
    
    "closeTags": { "whenOpening": false, "whenClosing": false, "indentTags": [] }
    

    JOSN object properties need to be saperated by a comma. Which is what the JSLint is telling you in that error.

    UPDATE

    Okay I suspected this, but thought you had only pasted partial code initially. Your preferences.json should actually look like this:

    {
            "closeBrackets": false,
            "debug.showErrorsInStatusBar": true,
            "closeTags": { "whenOpening": false, "whenClosing": false, "indentTags":[] } 
    }
    

    So your problem was that, all preferences need to go in the main {} object. Without that main wrapping {} the JSON is invalid.

    In future I recommend https://www.jsoneditoronline.org/ to validate and inspect your JSON strings.