I tried to use the json lexer in a *.rst document with sphinx. This one works:

.. code-block:: console

  key1: value,
  key2: value2,

But when I try to use json like this:

.. code-block:: json

  key1: value,
  key2: value2,

I get an error

WARNING: Could not lex literal_block as "json". Highlighting skipped.

I checked with pygmentize -L lexers | grep json but this returns, that json is on board. What is the problem here?

1 Answer 1


I was also wondering about this warning!

I looked into it and it turned out that the JSON lexer was available, but my code wasn't actually valid JSON, and therefore Sphinx disabled the lexer for this code snippet.

If you change your code block into valid JSON, highlighting should work again!

Note that (IIRC):

  • JSON doesn't allow comments
  • strings have to be quoted
  • dictionary values have to be enclosed in { and }
  • a comma after the final key-value-pair is not allowed

Note that if a lexer is not available, the warning message is different:

WARNING: Pygments lexer name 'xyz' is not known

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .