How to use the @stoplight/json.safeStringify function in @stoplight/json

To help you get started, we’ve selected a few @stoplight/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 stoplightio / spectral / src / spectral.ts View on Github external
public async runWithResolved(
    target: IParsedResult | object | string,
    opts: IRunOpts = {},
  ): Promise {
    let results: IRuleResult[] = [];

    let parsedResult: IParsedResult | IParsedResult>;
    if (!isParsedResult(target)) {
      parsedResult = {
        parsed: parseYaml(typeof target === 'string' ? target : safeStringify(target, undefined, 2)),
        getLocationForJsonPath: getLocationForJsonPathYaml,
        // we need to normalize the path in case path with forward slashes is given
        source: opts.resolve?.documentUri && normalize(opts.resolve.documentUri),
      };
    } else {
      parsedResult = target;
    }

    results = results.concat(formatParserDiagnostics(parsedResult.parsed.diagnostics, parsedResult.source));

    const documentUri = opts.resolve && opts.resolve.documentUri;
    const refDiagnostics: IRuleResult[] = [];

    const resolved = new Resolved(
      parsedResult,
      await this._resolver.resolve(parsedResult.parsed.data, {
github stoplightio / json-schema-viewer / src / components / Additional.tsx View on Github external
  const content = React.useMemo(() => safeStringify(additional, undefined, 2), [additional]);
github stoplightio / json-schema-viewer / src / components / Validations.tsx View on Github external
Object.entries(validations).map(([name, value]) => {
        if (typeof value === 'object') {
          value = safeStringify(value, undefined, 2);
        }

        return (
          
            {name}: {String(value)}
          
        );
      }),
    [validations]
github stoplightio / json-schema-viewer / src / PropValidations.tsx View on Github external
{Object.entries(validations).map(([k, v]) => {
          let type = typeof v;

          if (k === 'default' && ['object', 'boolean'].includes(type)) {
            v = safeStringify(v);

            type = typeof v;
          }

          if (type === 'boolean') {
            return (
              <div>
                {k}: {v.toString()}
              </div>
            );
          }

          if (type !== 'object') {
            return (
              <div>
                {k}: {v}</div>