How to use jmespath - 10 common examples

To help you get started, we’ve selected a few jmespath 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 noopkat / electric-io / public / js / lib / messagePropertyEvaluation.js View on Github external
function evaluate(path, input) {
  if (!path) {
    // Falsy paths are valid.
    // Return null to show an empty card.
    return { value: null, isValidPath: true };
  }

  if (path.substring(path.length - 1) === ".") {
    // jmespath.js has a bug where paths ending in "." aren't rejected by the parser.
    // https://github.com/jmespath/jmespath.js/issues/36
    // Return error.
    return { value: null, isValidPath: false };
  }

  try {
    const value = jmespath.search(input, path);
    return { value: value, isValidPath: true };
  } catch (error) {
    const errorName = (error.name || "").toLowerCase();
    if (
      errorName === "lexererror" ||
      errorName === "parsererror" ||
      errorName === "runtimeerror"
    ) {
      // The user entered a path that is not a valid JMESPath.
      // Return error.
      return { value: null, isValidPath: false };
    }
    throw error;
  }
}
github emdgroup / cfn-custom-resource / lambda.js View on Github external
request(args, ev, ctx, function(data) {
			let props = ev[rp][ev.RequestType] || ev[rp]['Create'];
			if (props.PhysicalResourceIdQuery) ev[pid] = jmespath.search(data, props.PhysicalResourceIdQuery);
			if (props[pid]) ev[pid] = props[pid];
			if (props.Attributes) data = jmespath.search(data, props.Attributes);
			response.send(ev, ctx, 'SUCCESS', data, ev[pid]);
		});
	}
github aws / aws-sdk-js-v3 / features / extra / hooks.js View on Github external
this.Then(/^the value at "([^"]*)" should be a list$/, function (path, callback) {
    var value = jmespath.search(this.data, path);
    this.assert.ok(Array.isArray(value), 'expected ' + util.inspect(value) + ' to be a list');
    callback();
  });
github awslabs / aws-api-gateway-developer-portal / lambdas / backend / meteringservice-preview-sdk-js-06-23-2016 / lib / resource_waiter.js View on Github external
path: function(resp, expected, argument) {
      var result = jmespath.search(resp.data, argument);
      return jmespath.strictDeepEqual(result,expected);
    },
github awslabs / aws-api-gateway-developer-portal / lambdas / backend / meteringservice-preview-sdk-js-06-23-2016 / lib / response.js View on Github external
cacheNextPageTokens: function cacheNextPageTokens() {
    if (Object.prototype.hasOwnProperty.call(this, 'nextPageTokens')) return this.nextPageTokens;
    this.nextPageTokens = undefined;

    var config = this.request.service.paginationConfig(this.request.operation);
    if (!config) return this.nextPageTokens;

    this.nextPageTokens = null;
    if (config.moreResults) {
      if (!jmespath.search(this.data, config.moreResults)) {
        return this.nextPageTokens;
      }
    }

    var exprs = config.outputToken;
    if (typeof exprs === 'string') exprs = [exprs];
    AWS.util.arrayEach.call(this, exprs, function (expr) {
      var output = jmespath.search(this.data, expr);
      if (output) {
        this.nextPageTokens = this.nextPageTokens || [];
        this.nextPageTokens.push(output);
      }
    });

    return this.nextPageTokens;
  }
github asyncapi / generator / lib / generator.js View on Github external
try {
      const sourceFile = path.resolve(baseDir, fileName);
      const relativeSourceFile = path.relative(this.templateDir, sourceFile);
      const targetFile = path.resolve(this.targetDir, relativeSourceFile);
      const relativeTargetFile = path.relative(this.targetDir, targetFile);

      if (this.isNonRenderableFile(relativeSourceFile)) {
        return await copyFile(sourceFile, targetFile);
      }

      const shouldOverwriteFile = await this.shouldOverwriteFile(relativeTargetFile);
      if (!shouldOverwriteFile) return;

      if (this.templateConfig.conditionalFiles && this.templateConfig.conditionalFiles[relativeSourceFile]) {
        const server = this.templateParams.server && asyncapiDocument.server(this.templateParams.server);
        const source = jmespath.search({
          ...asyncapiDocument.json(),
          ...{
            server: server ? server.json() : undefined,
          },
        }, this.templateConfig.conditionalFiles[relativeSourceFile].subject);

        if (source) {
          const validate = this.templateConfig.conditionalFiles[relativeSourceFile].validate;
          const valid = validate(source);
          if (!valid) return;
        }
      }

      const parsedContent = await this.renderFile(asyncapiDocument, sourceFile);
      const stats = fs.statSync(sourceFile);
      await writeFile(targetFile, parsedContent, { encoding: 'utf8', mode: stats.mode });
github josdejong / jsoneditor / src / js / previewmode.js View on Github external
me.executeWithBusyMessage(() => {
        const updatedJson = jmespath.search(json, query)
        me._setAndFireOnChange(updatedJson)
      }, 'transforming...')
    })
github awslabs / aws-api-gateway-developer-portal / lambdas / backend / meteringservice-preview-sdk-js-06-23-2016 / lib / request.js View on Github external
function wrappedCallback(err, data) {
      if (err) return callback(err, null);
      if (data === null) return callback(null, null);

      var config = self.service.paginationConfig(self.operation);
      var resultKey = config.resultKey;
      if (Array.isArray(resultKey)) resultKey = resultKey[0];
      var items = jmespath.search(data, resultKey);
      AWS.util.arrayEach(items, function(item) { callback(null, item); });
    }
github awslabs / aws-api-gateway-developer-portal / lambdas / backend / meteringservice-preview-sdk-js-06-23-2016 / lib / resource_waiter.js View on Github external
pathAny: function(resp, expected, argument) {
      var results = jmespath.search(resp.data, argument);
      if (!Array.isArray(results)) results = [results];
      var numResults = results.length;
      for (var ind = 0 ; ind < numResults; ind++) {
        if (jmespath.strictDeepEqual(results[ind], expected)) {
          return true;
        }
      }
      return false;
    },
github awslabs / aws-api-gateway-developer-portal / lambdas / backend / meteringservice-preview-sdk-js-06-23-2016 / lib / resource_waiter.js View on Github external
path: function(resp, expected, argument) {
      var result = jmespath.search(resp.data, argument);
      return jmespath.strictDeepEqual(result,expected);
    },

jmespath

JMESPath implementation in javascript

Apache-2.0
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis

Popular jmespath functions