276

Is there a way to nicely format/style JSON code in Github Wiki (i.e Markdown preferred)?

Something like this with few colors (or bold) and correct indentation:

http://www.freeformatter.com/json-formatter.html#ad-output

Mechanic
  • 5,015
  • 4
  • 15
  • 38
HP.
  • 19,226
  • 53
  • 154
  • 253

4 Answers4

586

Some color-syntaxing enrichment can be applied with the following blockcode syntax

```json
Here goes your json object definition
```

Note: This won't prettify the json representation. To do so, one can previously rely on an external service such as jsbeautifier.org and paste the prettified result in the wiki.

nulltoken
  • 64,429
  • 20
  • 138
  • 130
146
```javascript
{ "some": "json" }
```

I tried using json but didn't like the way it looked. javascript looks a bit more pleasing to my eye.

jc00ke
  • 2,435
  • 1
  • 21
  • 14
  • 19
    +1 - I like it so I can put `//` comments in the block for a little description. Since it's not valid JSON, the json block makes it ugly – NG. Oct 10 '13 at 23:04
  • 1
    Thanks for the hint, for some reason GitHub was making a simple JSON array unnecessarily ugly, now it's just fine :) – Kilian Aug 06 '14 at 21:37
44

2019 Github Solution

```yaml
{
   "this-json": "looks awesome..."
}
### Result
[![enter image description here][1]][1]

If you want to have keys a different colour to the values, set your language as `yaml`

[@Ankanna's answer][2] gave me the idea of going through [github's supported language list][3] and `yaml` was my best find. (No other language had keys a different colour to values on github).

Also you can use comments in `yaml` with `//`

  [1]: https://i.stack.imgur.com/ElxM5.png
  [2]: https://stackoverflow.com/a/46811028/2217801
  [3]: http://www.rubycoloredglasses.com/2013/04/languages-supported-by-github-flavored-markdown/
Jesse Reza Khorasanee
  • 3,140
  • 4
  • 36
  • 53
14

I encountered the same problem. So, I tried representing the JSON in different Language syntax formats.But all time favorites are Perl, js, python, & elixir.

This is how it looks.

The following screenshots are from the Gitlab in a markdown file. This may vary based on the colors using for syntax in MARKDOWN files.

JsonasPerl

JsonasPython

JsonasJs

JsonasElixir

Ankanna
  • 737
  • 2
  • 8
  • 21