JSON.stringify = (obj, human = false, highlight = false, level = 0) ->
_hl = (val, cls, tag = 'span') ->
val = '<' + tag + ' class="' + cls + '">' + val + '</' + tag + '>' if highlight
val
_str = (val) ->
regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
if (human || highlight) && regexp.test val
val = '<a href="' + val + '" target="_blank">' + val + '</a>'
_hl '"' + val + '"', 'string'
_tab = (open = true)->
return '' if !human
count = level
if open
count = level
else
count = level - 1
out = ''
if count >= 0
for i in [0..count]
if highlight
out += '<span class="tab"></span>'
else
out += '\t'
out
_line = ->
return '' if !human
'\n'
_out = (val, isArray) ->
if level == 0
val = _hl val, 'json', 'pre'
val
_key = (key, val, isArray) ->
return _line() + _tab() + val if isArray
if human
sep = ': '
else
sep = ':'
key = '"' + key + '"'
_line() + _tab() + _hl(key, 'property') + sep + val
_fix = (val) ->
if val == null
return _hl 'null', 'null'
type = typeof val
switch type
when 'boolean'
if val
x = 'true'
else
x = 'false'
out = _hl x, 'bool'
when 'number' then out = _hl val, 'number'
else out = _str val
if level == 0
out = _hl out, 'json'
out
if typeof obj != 'object' || !obj
return _out _fix obj
json = []
isArray = obj &&...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.