Struggling to refine the result set using jsonpath-plus

Utilizing the jsonpath-plus module (typescript), I am currently working on navigating to a specific object within a json document. The target object is nested several levels deep, requiring passage through 2 levels of arrays. When using the following jsonpath statement:

$..['gmd:DQ_AbsoluteExternalPositionalAccuracy']

The online jsonpath test website jsonpath.com returns the following result:

[
  {
    "gmd:nameOfMeasure": {
      "gco:CharacterString": "Difference to ICESat LE90"
    },
    "gmd:result": {
      "gmd:DQ_QuantitativeResult": {
        "gmd:valueUnit": {
          "@xlink:href": "http://www.opengis.net/def/uom/OGC/1.0/metre"
        },
        "gmd:value": {
          "gco:Record": {
            "gco:Real": "0.655608"
          }
        }
      }
    }
  }, 
  ...
 

In this scenario, I aim to retrieve the last object (with the label "Absolute vertical accuracy LE90"), but its position may vary. Adding a filter statement like

[?(@['gmd:nameOfMeasure']['gco:CharacterString']=="Absolute vertical accuracy LE90")]

to the original jsonpath expression results in the updated expression

$..['gmd:DQ_AbsoluteExternalPositionalAccuracy'][?(@['gmd:nameOfMeasure']['gco:CharacterString']=="Absolute vertical accuracy LE90")]

However, the filter does not affect the outcome. Experimenting with the same expression on the Jayway jsonpath implementation for java at successfully filters the result down to the desired object.

If anyone could provide guidance on properly filtering this result set using jsonpath-plus, it would be greatly appreciated.

Answer №1

To retrieve data from your sample JSON, you can use the following query:

$[?(@['gmd:nameOfMeasure']['gco:CharacterString']==="Absolute vertical accuracy LE90")]

This method has been effective for me; you may want to consider breaking down your queries into two separate steps.

As I only have access to the inner JSON data, it is difficult for me to provide a precise solution when querying the full JSON. However, keep in mind that JsonPath-Plus requires the JSON to be enclosed within square brackets:

[
  {"gmd:DQ_AbsoluteExternalPositionalAccuracy": [
    ...inner json      
  }
]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with decompressing the identical data using zlib (Z_BUF_ERROR)

Below is the Python code snippet I am working with: import zlib raw = bytes.fromhex("789C34C9410AC2301005D0BBFC752289A88BB94A53CAD8061B48D3329D2A1A7277DDB87BF02A14548E9C0DF63FD60DE49DC104AA98238BDE23EB908A467972065DFCF9FAFB4185C708EAD0053C58E38BDF769 ...

Instructions on transferring a JSON object to a RabbitMQ server

I am utilizing spring3 along with spring-amqp to transmit messages from my web application to a rabbitmq server. Currently, I can only send plain text to the rabbitmq server. However, I now desire to send my custom java object as JSON to the server. Upon ...

Firebase console does not show any console.log output for TypeScript cloud functions

I encountered an issue while using Typescript to write some Firebase cloud functions. Here is a snippet of my code: index.ts export * from "./Module1"; Module1.ts import * as functions from "firebase-functions"; export const test = functions.https.onR ...

Acquiring an element through ViewChild() within Angular

I am in need of a table element that is located within a modal. Below is the HTML code for the modal and my attempt to access the data table, which is utilizing primeng. <ng-template #industryModal> <div class="modal-body"> <h4>{{&a ...

Enhancing external TypeScript modules

Currently, I am delving into the realm of enhancing external modules in TypeScript. I am diligently studying the official documentation and the DefinitelyTyped guides, poring over examples, and so forth. At this point, my goal is to incorporate custom prop ...

Tips on displaying dynamic content on a single page with AngularJS 1.6

Just getting started with Angular and looking for a way to display dynamic content from a JSON file using AngularJS 1.6? Here's an example to help you out. News.json { "Articles": [ { "Title": "News 1", ...

How to use Angular 7 to send a JSON object as a parameter in an HTTP GET

I am attempting to send a JSON structure to a REST service from Angular in this manner: let test5var = { "test5var1": { "test5var2": "0317", "test5var3": "9556" }, ...

Fire the props.onChange() function when the TextField component is blurred

Currently, I am in the process of developing a NumberField component that has unique functionality. This component is designed to remove the default 0 value when clicked on (onFocus), allowing users to input a number into an empty field. Upon clicking out ...

When attempting to execute the 'npm start' command, an error was encountered stating "start" script is

Encountering an issue when running "npm start." Other users have addressed similar problems by adjusting the package.json file, so I made modifications on mine: "scripts": { "start": "node app.js" }, However, t ...

Exploring connections among Array Objects on a Map

Here are some JSON examples of Pokemon Battles: [ { "battleID": "1", "trainers": [ { "LastName": "Ketchum", "ForeName": "Ash" }, { "LastName": "Mason", ...

What was the reason for the removal of the `encoding` keyword argument from json.loads() function in Python 3.9?

The json package's official documentation explains: json.loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)¶ As of version 3.6: The s parameter now supports bytes or bytear ...

Modify data source with AngularJS when clicking a button

I have a webpage with a controller called 'listCtrl' that fetches data from "http://data.com/?region=north". app.controller('listCtrl', function ($scope, $http) { $http.get("http://data.com/?region=north").success(function (data) { ...

Compelling users to provide feedback on an App with the Ionic Framework

As a novice developer, I could use some assistance with implementing ratings in my app. My goal is to show menu items based on whether a user has given my app a 5-star rating. For instance, if a user gives a 5-star rating, I would assign the class "review ...

Getting an error message stating "Cannot update headers after they have been sent" while working with Node.js/Express and Axios

I encountered the following error and need assistance in finding a workaround. My goal is to output the data as a JSON object. Is there a solution to navigate around this error? I am currently copying and pasting from a tutorial, but I can't pinpoint ...

AntiforgeryToken validation issue when using Ajax in ASP.NET MVC

When looking at this View: @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "__AjaxAntiForgeryForm" })) { @Html.AntiForgeryToken() <div id='calendar'></div> <script src="~/Scripts/Services/Agenda.js" ...

What is the method for sending an HTTP GET request on a Blackberry device?

I'm looking to make a http GET request on the following URL in order to retrieve a JSON object. However, I'm unsure of the correct method to do so. Can anyone provide me with guidance? Thank you in advance. ...

Discover how to access JSON data using a string key in Angular 2

Trying to loop through JSON data in angular2 can be straightforward when the data is structured like this: {fileName: "XYZ"} You can simply use let data of datas to iterate over it. But things get tricky when your JSON data keys are in string format, li ...

Accordion's second child element experiencing issues with grid properties

I have set the parent element display:"Grid" and specified the gridColumnStart for my child elements as shown below. It seems to be working correctly for the first child element, but not for the second one. Please find my code attached: return ( ...

Errors occur with Metro bundler while utilizing module-resolver

Recently, I completed a project using the expo typescript template that runs on both iOS and Android platforms, excluding web. To enhance my development process, I established path aliases in the tsconfig.json file as shown below: "paths": { "@models/ ...

The process of exporting a dataframe to JSON in a particular format

Is there a way to modify the format of a json file exported using a downloadButton in a Shiny App? The current code successfully exports a data frame to json, but I want it to have a different structure. Here's the code that currently works: library(s ...