How to use the json.encode function in json

To help you get started, we’ve selected a few json examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kriskowal / narwhal-lib / lib / narwhal / tusk / commands / install.js View on Github external
var parts = fs.split(entry.getName());
                    parts.shift(); // name-project-comment ref dirname
                    var path = targetPath.join(fs.join.apply(null, parts));
                    path.dirname().mkdirs();
                    notes[name].files.push(path);
                    print(" + " + path);
                    path.write(entry.read('b'), 'b');
                });
            }

            // write package.json if it was not in the
            // archive
            var packageJson = targetPath.join('package.json');
            if (!packageJson.isFile())
                packageJson.write(
                    json.encode(catalog.packages[name], null, 4),
                    {'charset': 'UTF-8'}
                );

            // make bins executable and make symlinks
            //  in $SEA/bin
            var bin = targetPath.join('bin');
            if (bin.isDirectory())
                bin.list().forEach(function (name) {
                    var target = targetPath.join('bin', name);
                    target.chmod(0755);
                    var sea = tusk.getDirectory().join('bin');
                    var source = sea.join(name);
                    var relative = sea.to(target);
                    if (!source.linkExists() && !source.exists()) {
                        target.symlink(source);
                    }
github kriskowal / narwhal-lib / lib / narwhal / tusk / commands / install.js View on Github external
var parts = fs.split(entry.getName());
                    parts.shift(); // name-project-comment ref dirname
                    var path = targetPath.join(fs.join.apply(null, parts));
                    path.dirname().mkdirs();
                    notes[name].files.push(path);
                    print(" + " + path);
                    path.write(entry.read('b'), 'b');
                });
            }

            // write package.json if it was not in the
            // archive
            var packageJson = targetPath.join('package.json');
            if (!packageJson.isFile())
                packageJson.write(
                    json.encode(catalog.packages[name], null, 4),
                    {'charset': 'UTF-8'}
                );

            // make bins executable and make symlinks
            //  in $SEA/bin
            var bin = targetPath.join('bin');
            if (bin.isDirectory())
                bin.list().forEach(function (name) {
                    var target = targetPath.join('bin', name);
                    target.chmod(0755);
                    var sea = tusk.getDirectory().join('bin');
                    var source = sea.join(name);
                    var relative = sea.to(target);
                    if (!source.linkExists() && !source.exists()) {
                        target.symlink(source);
                    }
github dangoor / getjs / lib / getjs / workingenv.js View on Github external
_saveMetadata: function() {
        // Note: there should be some kind of file locking here!
        var rawdata = json.encode(this.metadata);
        rawdata = rawdata.toBinary();
        this.metadataFile.write(rawdata);
    }
}
github fibjs / fibjs / test / process / exec2.js View on Github external
var process = require('process');
var json = require('json');

console.log(json.encode(process.argv));
process.exitCode = 2;
github fibjs / fibjs / test / process / exec3.js View on Github external
var process = require('process');
var json = require('json');

console.log(json.encode(process.execArgv));
process.exitCode = 3;
github kriskowal / narwhal-lib / lib / narwhal / tusk.js View on Github external
exports.writeCatalog = function (catalog) {
    var catalogPath = exports.getCatalogPath();
    print('Writing ' + catalogPath);
    return catalogPath.write(
        json.encode(catalog, null, 4),
        {charset: 'utf-8'}
    );
};
github kriskowal / narwhal-lib / lib / narwhal / tusk.js View on Github external
exports.writeSources = function (sources) {
    return exports.getSourcesPath().write(
        json.encode(sources, null, 4),
        {charset: 'utf-8'}
    );
};
github dangoor / getjs / lib / getjs / install.js View on Github external
if (entry.name == "package.json") {
                destination = packagesDir.join(pack.name + ".json");
            } else {
                destination = root.join(entry.name);
            }
            
            filelist.push(root.to(destination));
            
            zf.saveFile(entry, destination);
        }
        zf.close();
        
        var fl = packagesDir.join(pack.name + ".filelist");
        filelist.push(root.to(fl));
        
        fl.write(json.encode(filelist));
    }
};
github kriskowal / narwhal-lib / lib / narwhal / tusk / init.js View on Github external
var activate = path.join('bin', 'activate.bash');
    fs.path(system.prefix).join('bin', 'activate.bash')
        .copy(activate);
    activate.relative().symlink(activate.resolve('activate'));

    path.join('README').touch();
    path.join('narwhal.conf')
        .write('NARWHAL_DEFAULT_ENGINE=' + system.engine);
    var packagePath = path.join('package.json');
    if (packagePath.isFile())
        util.complete(
            packageInfo, 
            json.decode(packagePath.read({charset:'utf-8'}))
        );
    packagePath.write(
        json.encode(packageInfo, null, 4),
        {charset:'utf-8'}
    );
});
github kriskowal / narwhal-lib / lib / narwhal / tusk.js View on Github external
exports.writeNotes = function (notes) {
    return exports.getNotesPath().write(
        json.encode(notes, null, 4),
        {charset: 'utf-8'}
    );
};