[] travis-url [] coveralls-url
nano-json
Well formatted(customizable) JSON like generator. Not compatible with pure JSON (smart strings/ids qouting).
Its very usefull for easy readble JS-objects dumps because you can define formats for sub-elements of objects deeply pretty.
API
id2str(id)
Returns quoted id
value if it's keyword or not identifier.
; // blah; // 'blah-blah'; // 'class'
str2str(str)
Returns quoted string. Automaticaly detects quotes symbols.
; // 'some string'; // 'some "" string with "double" quotes'; // "some '' string with 'single' quotes"
qstr(str)
Returns single qouted string.
; // 'some string'; // 'some "" string with "double" quotes'; // 'some \'\' string with \'single\' quotes'
dqstr(str)
Returns double quoted string.
; // "some string"; // "some \"\" string with \"double\" quotes"; // "some '' string with 'single' quotes"
js2str(obj, default_radix, unarray)
- obj
Object
; - default_radix
Number
- radix for number values (10 if undefined); - unarray
Boolean
- stringify root array as list (without square brackets).
Returns stringified object.
; // 10,20,30; // [10,20,30]; // [0xa,0x14,0x28]; // {a:1}
render(obj[, style[, indent[, tab]]])
- obj
Object
- style
Object
orString
String
- list format string: '###'Object
- { '':'', ['":':1], ['<>:':][, :]* }- '':
String
- current object list format string: '###' - '":':
Boolean
- force qouting of object keys flag - '<>:':
Number
- minimal width of object keys (will be padded by spaces) - '#':
Boolean
- enable array items index number comments - ID:
Object
- style for sub-object with identifier ID - '*':
Object
- style for array sub-items
- '':
- indent
String
- indent string ('' by default) - tab
String
- one indentation level spaces string
style samples
' #, # # '
var style = ' #, # # ';; // '[ 1, 2, 3 ]'; // '[ 1 ]'; // '[ ]'; // '{ a:1, b:2, c:3 }'; // '{ a:1 }'; // '{ }'
'#,##'
var style = '#,##';; // '[1,2,3]'; // '[1]'; // '[]'; // '{a:1,b:2,c:3}'; // '{a:1}'; // '{}'
'\n+#,\n+#\n=# '
Where the '+' symbol means next level of indentation.
var style = '\n+#,\n+#\n=# ';; // '[\n 1,\n 2,\n 3\n]'; // '[\n 1\n]'; // '[ ]'; // '{\n a:1,\n b:2,\n c:3\n}'; // '{\n a:1\n}'; // '{ }'