Skip to content

Commit

Permalink
Add square brackets in case of empty object
Browse files Browse the repository at this point in the history
  • Loading branch information
levindoneto committed Dec 29, 2017
1 parent ae4ad8d commit 41ed62d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/json2yaml.js
@@ -1,4 +1,4 @@
(function (self) {
(function (self) {
/*
* TODO, lots of concatenation (slow in js)
*/
Expand Down Expand Up @@ -47,7 +47,11 @@
}

function convertArray(obj, ret) {
if (obj.length === 0) {
ret.push('[]');
}
for (var i=0; i<obj.length; i++) {

var ele = obj[i];
var recurse = [];
convert(ele, recurse);
Expand Down Expand Up @@ -88,7 +92,7 @@
function convertString(obj, ret) {
ret.push(normalizeString(obj));
}

self.json2yaml = function(obj) {
if (typeof obj == 'string') {
obj = JSON.parse(obj);
Expand Down

0 comments on commit 41ed62d

Please sign in to comment.