It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

how to highlight JSON?

This question is in reference to Atlassian Documentation: Code Block Macro

Ask your question here...

4 answers

1 accepted

3 votes
Answer accepted

Your best bet is to choose "Javascript" from the syntax highlighting option. Otherwise you can install a custom SyntaxHighlighter brush like this one: http://donovanbrown.com/post/2016/01/10/Json-SyntaxHighLigther

This doesn't work for SyntaxHighlighter in the confluence code makro.

(Atlassian should improve the documentation and stop using outdated extensions like syntaxhighlighter)

Like # people like this

You could use JSON Viewer Macro for Confluence (Cloud & Server) 

You can use Code Syntax Highlighter plugin for Confluence cloud, which supports JSON.

Use this brush for JSON, save it as a file and add it via confluence code macro. Have fun ;-)

/**
* Author: Robert Galovic, AVINOC - www.avinoc.com
* License: GPL-2 | GPL-3
* JSON brush for confluence syntaxhighlighter
*/
SyntaxHighlighter.brushes.JSON = function()
{
var key_bool = 'true false null NULL';
this.regexList = [
{ regex: new RegExp(this.getKeywords(key_bool), 'gm'), css: 'value' },
{ regex: /[^\D](\d?\.?\d+)/gm, css: 'constants' },
{ regex: /((\"[\w]+\S*[^\\]\"))(?=[\:]|\s\:)/gm, css: 'variable' },
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' },
{ regex: /((\'[\w]+\S*[^\\]\'))(?=[\:]|\s\:)/gm, css: 'comments' },
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'comments' },
];
};
SyntaxHighlighter.brushes.JSON.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.JSON.aliases = ['json', 'Json', 'JSON'];

(If you like, you can customize it by changing the css definitions. Single quoted JSON entries wont comply to the standard, so I used "comments" css on them to mark them for being able later on to correct them easily)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

3,745 views 15 37
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you