How to use the jsonpath.apply function in jsonpath

To help you get started, we’ve selected a few jsonpath 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 Redocly / swagger-repo / lib / index.js View on Github external
function inlineHeaders(spec) {
  jpath.apply(spec, '$..[?(@.$ref)]', function(value) {
    if (!value.$ref.startsWith('#/headers')) {
      return value;
    }

    // TODO: throw if (!_.omit(value, '$ref').isEmpty())
    return jsonpointer.get(spec, value.$ref.substring(1));
  });
  delete spec.headers;
}
github misenhower / splatoon2.ink / src / app / updater / updaters / FestivalsUpdater.js View on Github external
async processData(regionData) {
        // Fix alpha/bravo images for the Chicken vs. Egg Splatfest.
        // For some reason these got swapped out with images that have an opaque background
        // even though they started out with transparent images.
        jsonpath.apply(regionData, '$..images.alpha', value => value.replace(
            "/images/festival/a070cc6b405b4fb335992d824097acd8.png",
            "/images/festival/06b3b0b7773d9e6c4ac0a5cc5371fc32.png"
        ));
        jsonpath.apply(regionData, '$..images.bravo', value => value.replace(
            "/images/festival/00e4c5fdccd3720d07127084fc1f4152.png",
            "/images/festival/d93df77468714c6211e9377f39a559f4.png"
        ));

        // Download result ranking data
        let festivalIds = jsonpath.query(regionData, '$.results..festival_id');
        for (let id of festivalIds) {
            let filename = `${this.getOutputPath()}/festivals/${this.region.toLowerCase()}-${id}-rankings.json`;

            // Have we already downloaded these rankings?
            if (!fs.existsSync(filename)) {
                let splatnet = new SplatNet(this.region);
                this.info(`Retrieving rankings for festival ID ${id}`);
                try {
                    let rankings  = await this.handleRequest(splatnet.getFestivalRankings(id));
                    writeJson(filename, rankings);
github APIs-guru / google-discovery-to-swagger / src / index.js View on Github external
});
  applyOnProperty(schemas, 'annotations', 'object', function (value) {
    let keys = _.keys(value);
    if (_.isEqual(keys, ['required']) && _.isArray(value.required))
      return undefined;
    return value;
  });

  //Google for some reason code minimum/maximum as strings
  function convertInt(value) {
    if (typeof value === 'string')
      return parseInt(value, 10);
    return value;
  }
  jp.apply(schemas, '$..*.minimum' , convertInt);
  jp.apply(schemas, '$..*.maximum' , convertInt);

  _.each(schemas, function (schema) {
    if (!('properties' in schema))
      return;

    _.each(schema.properties, function (property) {
      if ('default' in property) {
        property.default = processDefault(property);
      }
    });
  });

  return schemas;
}
github box / box-openapi / src / swaggerConverter.js View on Github external
paths.forEach(path => {
      path.pop()
      jp.apply(object, jp.stringify(path), (value) => {
        if (value.in === 'query') {
          value.items = { type: 'string' }
        }
        return value
      })
    })
  }
github kpi-wdc / dj / dj-libs / script / impl / var / get.js View on Github external
var getProperty = function(d, path) {
                var result = undefined;
                jp.apply(d, path, function(value) {
                    if (util.isUndefined(result)) {
                        result = value;
                    } else {
                        if (!util.isArray(result)) {
                            result = [result]
                        }
                        result.push(value)
                    }
                    return value
                })
                return result
            }
github kpi-wdc / dj / wdc_libs / data-processing / script / client / impl / var / set.js View on Github external
var getProperty = function(d,path){
      var result = undefined;
      jp.apply(d,path, function(value){
        if(util.isUndefined(result)){
          result = value;
        }else{
          if(!util.isArray(result)){
            result = [result]
          }
          result.push(value)
        }
        return value
      })
      return result
    }
github Azure / azure-openapi-validator / src / typescript / azure-openapi-validator / rules / utilities / rules-helper.ts View on Github external
export async function getResolvedJson(doc: any): Promise {
  try {
    const parser = new $RefParser()
    const docCopy = JSON.parse(JSON.stringify(doc))
    /*
     * remove x-ms-examples
     */
    apply(docCopy, `$..['x-ms-examples']`, e => null)
    return await parser.dereference(docCopy)
  } catch (err) {
    return
  }
}
github kpi-wdc / dj / dj-libs / script / impl / dps / lib.js View on Github external
var apply = function(lib, baseUrl){
    jp.apply(lib, "$..[?(@.import && @.type == 'extension')]", function(item) {
        item["import"] = baseUrl["import"] + item["import"];
        return item
    });    
    jp.apply(lib, "$..[?(@.call && @.type == 'extension')]", function(item) {
        item["call"] = baseUrl["call"] + item["call"];
        return item
    });    
    
    return lib;
}
github APIs-guru / google-discovery-to-swagger / GoogleDiscovery2Swagger.js View on Github external
function processDefinitions(schemas) {
  if (schemas == undefined)
    return undefined;

  schemas = api.v4(schemas);
  jp.apply(schemas, '$..*["$ref"]' , function (value) {
    //if $ref isn't string it mean that this isn't reference
    //it something called '$ref', this happens in 'discovery:v1'.
    if (typeof value !== 'string')
      return value;
    return fixRef(value);
  });

  jp.apply(schemas, '$..*.type' , function (value) {
    if (value === 'any')
      return undefined;
    return value;
  });

  //Google for some reason code minimum/maximum as strings
  function convertInt(value) {
    if (typeof value === 'string')

jsonpath

Query JavaScript objects with JSONPath expressions. Robust / safe JSONPath engine for Node.js.

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis