Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the color of the JSON `Key` in Sublime Text2

So I've added:

    <dict>
        <key>name</key>
        <string>JSON Key</string>
        <key>scope</key>
        <string>meta.structure.dictionary.json string2.quoted.double.json</string>
        <key>settings</key>
        <dict>
            <key>foreground</key>
            <string>#00FF00</string>
        </dict>
    </dict>

to my color scheme called custom.tmTheme and I've added:

    <key>string2</key>
    <dict>
        <key>begin</key>
        <string>"</string>
        <key>beginCaptures</key>
        <dict>
            <key>0</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.string2.begin.json</string>
            </dict>
        </dict>
        <key>end</key>
        <string>"\s.:</string>
        <key>endCaptures</key>
        <dict>
            <key>0</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.string2.end.json</string>
            </dict>
        </dict>
        <key>name</key>
        <string>string2.quoted.double.json</string>
        <key>patterns</key>
        <array>
            <dict>
                <key>match</key>
                <string>(?x:                # turn on extended mode
                 \\                # a literal backslash
                 (?:               # ...followed by...
                   ["\\/bfnrt]     # one of these characters
                   |               # ...or...
                   u               # a u
                   [0-9a-fA-F]{4}  # and four hex digits
                 )
               )</string>
                <key>name</key>
                <string>constant.character.escape.json</string>
            </dict>
            <dict>
                <key>match</key>
                <string>\\.</string>
                <key>name</key>
                <string>invalid.illegal.unrecognized-string-escape.json</string>
            </dict>
        </array>
    </dict>

to a JSON-test.tmLanguage file in my packages folder, but yet I still don't see green keys.

Does anyone have any idea where I went wrong?

like image 253
Jason Nichols Avatar asked Sep 12 '25 19:09

Jason Nichols


1 Answers

You don't need to create or modify a .tmLanguage file, you should be able to do this simply using the JavaScript -> JSON syntax. Modify your .tmTheme like so:

<dict>
    <key>name</key>
    <string>JSON Key</string>
    <key>scope</key>
    <string>meta.structure.dictionary.json string.quoted.double.json -meta.structure.dictionary.value.json</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#00FF00</string>
    </dict>
</dict>

and you should be all set. It will highlight all strings contained within JSON dictionaries, but not if the scope contains meta.structure.dictionary.value.json, so it will only highlight the keys.

like image 121
MattDMo Avatar answered Sep 15 '25 08:09

MattDMo