How to use the jsonpath.query 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 Sundly / sundly / src / lib / parse_cda.js View on Github external
function getTimeline(result) {
  const entries = jp.query(result, '$.ClinicalDocument.entry')[0]
  const vitalSigns = jp.query(entries, '$[?(@.organizer.code.__code=="46680005")]')
  const observations = jp.query(vitalSigns, '$..observation')
  const keys = {
    'Height': 'height',
    'Body weight Measured': 'weight',
    'Heart rate': 'heart_rate',
    'Body Temperature': 'temperature'
  }
  const obTimeline = observations.map((observation) => {
    const effectiveTime = jp.query(observation, '$.effectiveTime.low.__value')[0]
    const datetime = moment(effectiveTime, 'YYYYMMDDTHHmmss-Z').format()
    const name = jp.query(observation, '$.code.__displayName')[0]
    const value = jp.query(observation, '$.value.__value')[0]
    // ToDo: Convert value scale based on units
    // const unit = jp.query(observation, '$.value.__unit')[0]

    return { datetime, [keys[name]]: value}
  })
github egovernments / egov-services / web / react-pgr-web-v2 / src / components / non-framework / works / transaction / spilloverAE / spilloverAE.js View on Github external
function(response) {
            if (response) {
              let keys = jp.query(response, splitArray[1].split('|')[1]);
              let values = jp.query(response, splitArray[1].split('|')[2]);
              let dropDownData = [];
              for (var k = 0; k < keys.length; k++) {
                let obj = {};
                obj['key'] = keys[k];
                obj['value'] = values[k];
                dropDownData.push(obj);
              }

              dropDownData.sort(function(s1, s2) {
                return s1.value < s2.value ? -1 : s1.value > s2.value ? 1 : 0;
              });
              dropDownData.unshift({ key: null, value: '-- Please Select --' });
              setDropDownData(value.jsonPath, dropDownData);
              setDropDownOriginalData(value.jsonPath, response);
            }
github egovernments / egov-services / web / react-pgr-web-v2 / src / components / framework / components / UiWindowSelectField.js View on Github external
function(response) {
          if (response) {
            let queries = splitArray[1].split('|');
            let keys = jp.query(response, queries[1]);
            let values = jp.query(response, queries[2]);
            let otherPair = [];
            if (item.hasOwnProperty('isKeyOtherPair') && item.isKeyOtherPair) {
              otherPair = jp.query(response, `$..${item.isKeyOtherPair}`);
            }
            if (item.hasOwnProperty('isCurrentYear') && item.isCurrentYear) {
              var date = new Date();
              var currentYear = date.getFullYear();
              keys = _.filter(keys, function(key) {
                return key <= currentYear;
              });
              values = _.filter(values, function(value) {
                return value <= currentYear;
              });
            }

            let others = [];
            if (queries.length > 3) {
              for (let i = 3; i < queries.length; i++) {
                others.push(jp.query(response, queries[i]) || undefined);
github egovernments / egov-services / web / react-pgr-web-v2 / src / components / framework / components / UiTable.js View on Github external
function(response) {
              let keys = jp.query(response, splitArray[1].split('|')[1]);
              let values = jp.query(response, splitArray[1].split('|')[2]);
              let dropDownData = {};
              for (var k = 0; k < keys.length; k++) {
                dropDownData[keys[k]] = values[k];
              }
              self.setState(
                {
                  [self.props.resultList.resultHeader[m].label]: dropDownData,
                },
                function() {}
              );
            },
            function(err) {}
github egovernments / egov-services / web / react-pgr-web / src / components / non-framework / asset / transactionTransfer.js View on Github external
if(!getVal(values[i])) {
            _flag = 1;
          }
        }

        if(isDate && e.target.value && [12, 13].indexOf((e.target.value+"").length) == -1) {
          _flag = 1;
        }

        if(_flag == 0) {
          if(!eval(str)) {
            return this.props.toggleSnackbarAndSetText(true, translate(expErr), false, true);
          }
        }
      }
      let depedants=jp.query(obj,`$.groups..fields[?(@.jsonPath=="${property}")].depedants.*`);
      if(depedants.length === 0)
        depedants = jp.query(obj,`$.groups..fields[?(@.type=="tableList")].tableList.values[?(@.jsonPath == "${property}")].depedants.*`);

      this.checkIfHasShowHideFields(property, e.target.value);
      this.checkIfHasEnDisFields(property, e.target.value);
      handleChange(e,property, isRequired, pattern, requiredErrMsg, patternErrMsg);

      _.forEach(depedants, function(value, key) {
            if (value.type == "dropDown") {
                let splitArray = value.pattern.split("?");
                let context = "";
          			let id = {};
          			for (var j = 0; j < splitArray[0].split("/").length; j++) {
          				context+=splitArray[0].split("/")[j]+"/";
          			}
github egovernments / egov-services / web / react-pgr-web / src / components / non-framework / inventory / common / CustomSearch.js View on Github external
Api.commonApiPost(context,id).then(function(response) {
                    if(response) {
                      let keys=jp.query(response,splitArray[1].split("|")[1]);
                      let values=jp.query(response,splitArray[1].split("|")[2]);
                      let dropDownData=[];
                      for (var k = 0; k < keys.length; k++) {
                          let obj={};
                          obj["key"]=keys[k];
                          obj["value"]=values[k];
                          dropDownData.push(obj);
                      }

                      dropDownData.sort(function(s1, s2) {
                        return (s1.value < s2.value) ? -1 : (s1.value > s2.value) ? 1 : 0;
                      });
                      dropDownData.unshift({key: null, value: "-- Please Select --"});
                      setDropDownData(value.jsonPath, dropDownData);
                    }
                  },function(err) {
github ylacaute / ez-Dashing / ez-client / src / main / js / utils / json-mapper.js View on Github external
function mapSimpleType(propType, jsonPathQuery, jsonResponse) {
  let jsonPathValue = JSONPath.query(jsonResponse, jsonPathQuery);
  if (propType !== "array") {
    jsonPathValue = TypeUtils.convert(jsonPathValue[0], propType);
  }
  return jsonPathValue;
}
github egovernments / egov-services / web / react-pgr-web-v2 / src / components / non-framework / perfManagement / charts / kpiBarchart.js View on Github external
return jp.query(finYears, '$.kpiValues[*]').map((kpis, index) => {
                    return {
                        ulbName: jp.query(ulbs, '$.ulbName').join(''),
                        finYear:jp.query(finYears, '$.finYear').join(''),
                        kpiName:jp.query(kpis, '$.kpi.name').join(''),
                        target: parseInt(jp.query(kpis, '$.kpi.kpiTarget.targetValue').join('')),
                        value: parseInt(jp.query(kpis, '$.consolidatedValue').join(''))
                    }
                })
            })
github Kong / insomnia / plugins / insomnia-plugin-response / index.js View on Github external
function matchJSONPath(bodyStr, query) {
  let body;
  let results;

  try {
    body = JSON.parse(bodyStr);
  } catch (err) {
    throw new Error(`Invalid JSON: ${err.message}`);
  }

  try {
    results = jq.query(body, query);
  } catch (err) {
    throw new Error(`Invalid JSONPath query: ${query}`);
  }

  if (results.length === 0) {
    throw new Error(`Returned no results: ${query}`);
  } else if (results.length > 1) {
    throw new Error(`Returned more than one result: ${query}`);
  }

  if (typeof results[0] !== 'string') {
    return JSON.stringify(results[0]);
  } else {
    return results[0];
  }
}
github egovernments / egov-services / web / react-pgr-web / src / components / non-framework / inventory / common / CustomTransaction.js View on Github external
}
      return str.join("");
    }
    let depedants = jp.query(obj, `$.groups..fields[?(@.jsonPath=="${property}")].depedants.*`);
    let dependantIdx;
    if (depedants.length === 0 && property) {
      let currentProperty = property;
      dependantIdx = findLastIdxOnJsonPath(property);
      if (dependantIdx !== undefined)
        currentProperty = replaceLastIdxOnJsonPath(property, 0); //RESET INDEX 0 TO FIND DEPENDANT FIELDS FROM TEMPLATE JSON
      depedants = jp.query(obj, `$.groups..fields[?(@.type=="tableList")].tableList.values[?(@.jsonPath == "${currentProperty}")].depedants.*`);

      //Changes to handle table sum
      var jpathname = property.substr(0, property.lastIndexOf("[") + 1) + '0' + property.substr(property.lastIndexOf("[") + 2);

      var dependency = jp.query(obj, `$.groups..values[?(@.jsonPath=="${jpathname}")].dependency`);
      if (dependency.length > 0) {
        let _formData = { ...this.props.formData
        };
        if (_formData) {
          let field = property.substr(0, property.lastIndexOf("["));
          let last = property.substr(property.lastIndexOf("]") + 2);
          let curIndex = property.substr(property.lastIndexOf("[") + 1, 1);

          let arrval = _.get(_formData, field);
          if (arrval) {
            let len = _.get(_formData, field).length;

            let amtsum = 0;
            let svalue = "";
            for (var i = 0; i < len; i++) {
              let ifield = field + '[' + i + ']' + '.' + last;

jsonpath

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

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis