How to use json - 10 common examples

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 fibjs / fib-app / lib / classes / index.js View on Github external
}
            // check classname
            const cls = db.models[classname];
            if (cls === undefined)
                return fill_error(req, err_info(4040001, {
                    classname: classname
                }));
            var _req = {
                session: req.session,
                query: req.query.toJSON(),
                request: req
            };
            var where = _req.query.where;
            if (where !== undefined)
                try {
                    _req.query.where = json.decode(where);
                }
                catch (e) {
                    return fill_error(req, err_info(4000003));
                }
            var keys = _req.query.keys;
            if (keys !== undefined && typeof keys === 'string')
                _req.query.keys = keys.split(',');
            var result;
            try {
                result = func.apply(undefined, [_req, db, cls].concat(earg, [data]));
            }
            catch (e) {
                console.error(e.stack);
                if (e.type === 'validation') {
                    result = {
                        error: {
github kissygalleryteam / offline / 2.5.0 / build / index.js View on Github external
_saveToBrowser: function () {
		var flag = true;
		try {
			oIeOffline.setAttribute(TIME_DEADLINE, Json.stringify(oDeadline));
			oIeOffline.setAttribute(SINGLE_KEY, Json.stringify(oGlobal));
			oIeOffline.save(IE_OFFLINE);
		} catch (e) {
			// 磁盘已满或权限不足等问题
			flag = false;
		}
		return flag;
	}
});	//re.init();
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 WebReflection / lightercollective / index.js View on Github external
#!/usr/bin/env node
// (C) Andrea Giammarchi - @WebReflection (ISC)
var path = require('path');

try {
  var json = path.resolve('./package.json');
  var package = require(json);
  // be sure collective is there and refers to lightercollective
  var collective = (
    (package.dependencies || {}).lightercollective ||
    (package.devDependencies || {}).lightercollective
  ) && package.collective;
  if (
    !collective ||
    -1 < ['silent', 'error', 'warn'].indexOf(process.env.npm_config_loglevel) ||
    /^(?:1|true|yes|y)$/i.test(process.env.DISABLE_OPENCOLLECTIVE)
  ) {
    throw 0;
  }
  if (collective.logo) {
    if (/^(https?):/.test(collective.logo))
      require(RegExp.$1)
        .get(collective.logo, function (response) {
          if (response.statusCode === 200) {
            response.setEncoding('utf8');
            var data = [];
            response.on('data', function (chunk) { data.push(chunk); });
            response.on('end', function () { showLogo(data.join('')) });
github WebReflection / lightercollective / index.js View on Github external
#!/usr/bin/env node
// (C) Andrea Giammarchi - @WebReflection (ISC)
var path = require('path');

try {
  var json = path.resolve('./package.json');
  var package = require(json);
  // be sure collective is there and refers to lightercollective
  var collective = (
    (package.dependencies || {}).lightercollective ||
    (package.devDependencies || {}).lightercollective
  ) && package.collective;
  if (
    !collective ||
    -1 < ['silent', 'error', 'warn'].indexOf(process.env.npm_config_loglevel) ||
    /^(?:1|true|yes|y)$/i.test(process.env.DISABLE_OPENCOLLECTIVE)
  ) {
    throw 0;
  }
  if (collective.logo) {
    if (/^(https?):/.test(collective.logo))
      require(RegExp.$1)
        .get(collective.logo, function (response) {
          if (response.statusCode === 200) {
            response.setEncoding('utf8');
            var data = [];
github WebReflection / lightercollective / index.js View on Github external
#!/usr/bin/env node
// (C) Andrea Giammarchi - @WebReflection (ISC)
var path = require('path');

try {
  var json = path.resolve('./package.json');
  var package = require(json);
  // be sure collective is there and refers to lightercollective
  var collective = (
    (package.dependencies || {}).lightercollective ||
    (package.devDependencies || {}).lightercollective
  ) && package.collective;
  if (
    !collective ||
    -1 < ['silent', 'error', 'warn'].indexOf(process.env.npm_config_loglevel) ||
    /^(?:1|true|yes|y)$/i.test(process.env.DISABLE_OPENCOLLECTIVE)
  ) {
    throw 0;
  }
  if (collective.logo) {
    if (/^(https?):/.test(collective.logo))
      require(RegExp.$1)
        .get(collective.logo, function (response) {
          if (response.statusCode === 200) {
            response.setEncoding('utf8');
            var data = [];
            response.on('data', function (chunk) { data.push(chunk); });
github kissyteam / kissy / src / router / demo / mods / sync.js View on Github external
if (index > -1) {
                        store.splice(index, 1);
                    }
                    break;
                case 'update':
                    id = self.get('id');
                    index = findById(store, id);
                    if (index > -1) {
                        store[index] = self.toJSON();
                    }
                    break;
            }

            if (method !== 'read' && window.localStorage) {
                try {
                    window.localStorage.setItem(KEY, Json.stringify(store));
                } catch (e) {
                    // QUOTA_EXCEEDED_ERR
                    S.log(e, 'error');
                }
            }

            STORE = store;

            if (error) {
                if (options.error) {
                    options.error(null, error);
                }
            }

            else if (options.success) {
                options.success(ret);
github kissyteam / kissy / src / editor / sub-modules / plugin / draft / src / draft.js View on Github external
_getDrafts: function () {
        var self = this;
        if (!self.drafts) {
            var str = localStorage.getItem(self._getSaveKey()),
                drafts = [];
            if (str) {
                // 原生 localStorage 必须串行化
                drafts = (localStorage === window.localStorage) ?
                    Json.parse(util.urlDecode(str)) : str;
            }
            self.drafts = drafts;
        }
        return self.drafts;
    },
github kriskowal / narwhal-lib / lib / narwhal / tusk / update.js View on Github external
// use an old one if it's no longer available
                log.error("Unable to download a fresh copy of catalog " + url + ".");
            }
        }

        // try to read the downloaded or stale copy
        try {
            var json = httpStore.read(url, {"charset": "UTF-8"});
        } catch (exception) {
            log.error("HttpError getting " + url + ".");
            return;
        }

        // try to parse the source file
        try {
            include = JSON.decode(json);
        } catch (exception) {
            log.error("SyntaxError in " + url + ".");
            return;
        }

        if (include.version < TUSK.minCatalogVersion) {
            log.error("Catalog at " + url + " is obsolete.");
            return;
        }

        catalogs[url] = include;
        include.url = url;
        // validate the catalog
        // transitively grab sub-catalogs
        exports.getCatalogs(include, catalogs, order, useCache, log);
    });