Home Download Buy Blog Forum Support

JSON syntax highlighting does not work

JSON syntax highlighting does not work

Postby piksel on Sat Aug 25, 2012 9:39 am

Hello, when I open a .json-file ST automatically selects JSON syntax hightlighting, but it looks the same as no highlighting (ie only one color). But if I change the highlighting to JavaScript, it looks fine.

Any tips on how to fix this?

Image
JSON highlighting to the left, JavaScript highlighting to the right
piksel
 
Posts: 8
Joined: Sat Aug 25, 2012 9:31 am

Re: JSON syntax highlighting does not work

Postby ReinierK on Sat Aug 25, 2012 2:21 pm

Looks fine to me, your JSON file only consists of strings (which are light grey in JSON syntax highlighting).
Maybe your real question is if it's possible to give JSON the same highlighting as JavaScript, which is a little odd of course. ;-)

What colors do you get when you input numbers in your JSON file? If they turn purple (assuming you use the Monokai color scheme), then it works fine.
ReinierK
 
Posts: 23
Joined: Fri Aug 24, 2012 8:27 pm

Re: JSON syntax highlighting does not work

Postby piksel on Wed Sep 05, 2012 11:54 am

Yeah, both errors and numbers are in a different color, so I guess it is working. I guess what I want is for strings to be in another color, or commas, or moustaches. Most of my json-files are strings in objects and arrays, so for me everything is always in just one color.

Do you (or anyone else) know why javascript highlights strings but JSON does not?
I actually think I will set .json-files to javascript highlighting for now even though its odd.

Cheers!

UPDATE There is a special tag for json-strings in the theme definition; "string.quoted.double.json", so I just created a remix of the theme with another color on the json-strings.
piksel
 
Posts: 8
Joined: Sat Aug 25, 2012 9:31 am

Re: JSON syntax highlighting does not work

Postby wrlee on Tue Jul 30, 2013 8:56 pm

I found the JSON highlighting in TextWrangler (I think it is the default) useful. It differentiates between a string used as a tag-name from strings that are values. This makes JSON much easier to read in TextWrangler than Sublime. I'm new to Sublime… does the syntax description differentiate between these two types of strings (which can then be highlighted in the themes, distinctly)?
wrlee
 
Posts: 2
Joined: Mon Jul 29, 2013 9:15 pm

Re: JSON syntax highlighting does not work

Postby codedungeon on Wed Jul 31, 2013 3:37 am

Would you be willing to share what you have come up with? I have been searching all over for some simple JSON formatting. Does it work when JSON is auto selected?
codedungeon
 
Posts: 1
Joined: Wed Jul 31, 2013 3:36 am

Re: JSON syntax highlighting does not work

Postby WickyNilliams on Mon Nov 04, 2013 11:57 pm

For anyone else who stumbles on this page wondering how to give strings in JSON a different colour...

Find your current theme file. I was using the monokai soda theme, which I found in my user packages. Open up your thTheme file. I then found the following XML (simply searched for "json")

Code: Select all
<dict>
    <key>name</key>
    <string>JSON String</string>
    <key>scope</key>
    <string>meta.structure.dictionary.json string.quoted.double.json</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#CFCFC2</string>
    </dict>
</dict>

And then I altered it to be the following. Note I've commented out the previous value and added the standard sublime yellow:

Code: Select all
<dict>
    <key>name</key>
    <string>JSON String</string>
    <key>scope</key>
    <string>meta.structure.dictionary.json string.quoted.double.json</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <!-- <string>#CFCFC2</string> -->
        <string>#E6DB74</string>
    </dict>
</dict>


Save your theme and all should then work :)

I even think you might be able to edit the json tmLanguage file to capture string keys differently to string values - but that's for another day!
WickyNilliams
 
Posts: 1
Joined: Mon Nov 04, 2013 11:53 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 18 guests