How to use json-stringify-safe - 10 common examples

To help you get started, we’ve selected a few json-stringify-safe 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 storybookjs / storybook / src / client / synced_store.js View on Github external
setData(fields) {
    Object
      .keys(fields)
      .forEach(key => {
        this._data[key] = fields[key];
      });

    this._data.__lastUpdated = Date.now();
    // In page-bus, we must send non-identical data.
    // Otherwise, it'll cache and won't trigger.
    // That's why we are setting the __lastUpdated value here.
    this._bus.emit(this.getDataKey(), stringify(this.getData()));
    this._handlers.forEach(handler => handler(this.getData()));
  }
github planttheidea / fast-stringify / DEV_ONLY / index.tsx View on Github external
ReactStatefulClass: StatefulComponent,
  // @ts-ignore
  ReactStatefulElement: ,
  ReactStatelessClass: StatelessComponent,
  ReactStatelessElement: ,
};

console.group('circular');
console.log(stringify(new Circular('foo')));
console.log(safeStringify(new Circular('foo')));
console.groupEnd();

console.group('window');
console.log(stringify(window));
console.log(safeStringify(window));
console.groupEnd();

console.group('object of many types');
console.log(stringify(object, null, 2));
console.log(safeStringify(object, null, 2));
console.groupEnd();

console.group('custom replacer');
console.log(stringify(object.arrayBuffer, (key, value) => Buffer.from(value).toString('utf8')));
console.groupEnd();

console.group('custom circular replacer');
console.log(
  stringify(new Circular('foo'), null, null, (key, value, refCount) => `Ref-${refCount}`),
);
console.groupEnd();
github planttheidea / fast-stringify / DEV_ONLY / index.tsx View on Github external
uint8ClampedArray: new Uint8ClampedArray([1, 2, 3]),
  weakMap: new WeakMap().set({}, 7).set({ foo: 3 }, ['abc']),
  weakSet: new WeakSet().add({}).add({ foo: 'bar' }),
  doc: document,
  win: window,

  ReactStatefulClass: StatefulComponent,
  // @ts-ignore
  ReactStatefulElement: ,
  ReactStatelessClass: StatelessComponent,
  ReactStatelessElement: ,
};

console.group('circular');
console.log(stringify(new Circular('foo')));
console.log(safeStringify(new Circular('foo')));
console.groupEnd();

console.group('window');
console.log(stringify(window));
console.log(safeStringify(window));
console.groupEnd();

console.group('object of many types');
console.log(stringify(object, null, 2));
console.log(safeStringify(object, null, 2));
console.groupEnd();

console.group('custom replacer');
console.log(stringify(object.arrayBuffer, (key, value) => Buffer.from(value).toString('utf8')));
console.groupEnd();
github embark-framework / embark / packages / core / console / src / lib / index.ts View on Github external
this.executeCmd(req.body.command, (err: any, result: any) => {
        if (err) {
          return res.send({ result: err.message || err });
        }
        let response = result;
        if (typeof result !== "string") {
          response = stringify(result, jsonFunctionReplacer, 2);
        } else {
          // Avoid HTML injection in the Cockpit
          response = escapeHtml(response);
        }
        const jsonResponse = {result: response};
        if (res.headersSent) {
          return res.end(jsonResponse);
        }
        return res.send(jsonResponse);
      });
    });
github embark-framework / embark / packages / core / structlog / src / index.js View on Github external
updateRecord(id, data) {
    // DB[id] = { ...DB[id], ...data }
    fs.appendFileSync(this.logfile, "\n" + stringify(data, jsonFunctionReplacer, 0));
  }
github rapid7 / le_node / src / serialize.js View on Github external
if (!_.isObject(val)) {
          newTarget[joinedKey] = val;
        } else if (!arraysToo && _.isArray(val)) {
          newTarget[joinedKey] = val.map(newVal => {
            if (!_.isObject(newVal)) return newVal;

            return _.reduce(newVal, _.bind(_flat, []), {});
          });
        } else {
          _.reduce(val, _.bind(_flat, keyContext), newTarget);
        }

        return newTarget;
      }, []), {});

      return jsonSS(flatObj);
    };
github Autarc / redux-sync / src / store.js View on Github external
function sendMessage (options, scope, action, patch) {
  scope && scope.postMessage('redux-sync:' + stringify({
    id: options.id,
    trigger: action,
    patch
  }), '*')
}
github fkling / astexplorer / website / src / components / TransformOutput.js View on Github external
key="error"
            lineNumbers={false}
            readOnly={true}
            value={this.state.error.message}
          /> : (
            typeof this.state.result === 'string' ?
             :
            
          )
        }
      
    );
  }
}
github planttheidea / crio / src / CrioArray.js View on Github external
toString(serializer, indent) {
    return stringify(this, serializer, indent);
  }
github tedeh / jayson / lib / utils.js View on Github external
Utils.JSON.stringify = function(obj, options, callback) {
  let replacer = null;
  let str = null;
  options = options || {};

  if(isFunction(options.replacer)) {
    replacer = options.replacer;
  }

  try {
    str = JSONstringify.apply(JSON, compact([obj, replacer]));
  } catch(err) {
    return callback(err);
  }

  callback(null, str);
};

json-stringify-safe

Like JSON.stringify, but doesn't blow up on circular refs.

ISC
Latest version published 10 years ago

Package Health Score

71 / 100
Full package analysis

Popular json-stringify-safe functions