How does jsonpath truncate a character string? - jsonpath

{
"pubDesc": "1994-09-13美国上映"
}
All I want is 1994-09-13
Does jsonpath support this function?

Related

How to extract value using a JSON Path Expression from key that contains a quote?

I have the following JSON:
{ "\"a\"" : 456 }
I want to use jsonpath npm with method value to extract the value 456.
What is the jsonpath expression to extract this value?
I tried jsonpath.value({ "\"a\"" : 456 }, '$["\\"a\\""]') But it returns undefined.
In general, my question is how to write a jsonpath expression to extract an object whose key contains a quote.

How to convert string to list in JSONPath notation?

The JSON in line 5 in the Parameters section of the screenshot uses JSONPath notation in AWS Step Functions. The key is "Values.$" and the value is a JSONPath that selects a string "$". However, I need to pass in a LIST not a STRING. The value that $ selects is a string.
If I put brackets around, it no longer recognizes that I'm using JSONPath notation and simply passes in the dollar sign character instead of gets the value from inputs.
How can I use JSONPath notation and pass in a string as a list?
Should be able to use the States.Array Intrinsic Function since Parameters is a Payload Template
{
"Filters": [{
"Name": "replication-task-arn",
"Values.$": "States.Array($)"
}],
"MaxRecords": 20,
"WithoutSettings": true
}

JSONPath - Filter expression to print a field if an array contains a string

I have the following JSON and am trying to write a JSON Path expression which will return me the isbn number when I have a id of either '123456789' or '987654321'. I tried the following but this did not work. Can anybody tell me what I am doing wrong please. Thanks in advance
JSON Path Expression
$.books[?(#.ids== '123456789' )].isbnNumber
JSON
{
"books": [{
"title": "10",
"isbnNumber": "621197725636",
"ids": [
"123456789",
"987654321"
]
}]
}
The (more traditional) JSONPath implementations that stick close(r) to Goessner's reference specification do not offer handy functions like in which are available in extended implementations like JayWay's JSONPath.
Using Gatling's JSONPath, one thing we could do if the positions of the Ids in question are fixed is accessing their respective indices directly to make the comparison:
$.books[?(#.ids[0] == "123456789" || #.ids[1] == "987654321")].isbnNumber
This will give you the desired result of your example; however, some books only have one of the two indices, or they Id to compare to shows up on a different position it won't work.

JsonPath (jayway) to return scalar as array

I have struggles to craft working jsonpath (Jayway https://jsonpath.herokuapp.com/) where property (scalar) is returned as array.
For input
{
"a":{
"b":"valueofb"
}
}
I would like obtain array: ["valueofb"] NOT just valueofb
I have found an option how to do it.
$..a.b

Look for Value in Multiple Keys with JSONPath

With JSONPath, how can you extract a single value from a list of known keys?
For example, I want to write one JSON path expression that can extract Sean from all three of these JSON documents:
{ "firstName": "Sean" }
{ "first_name": "Sean" }
{ "first_name": "Sean", "firstName": "Sean" }
This example is a little contrived, but I have an actual use case that requires this behavior.
The best I can come up with is the expression $.firstName,first_name which will work for #1 and #2 but returns an array for #3 — and I just want the first value that matches.
Basically, I’m looking for a JSONPath extract expression that simulates this JavaScript code:
json.firstName || json.first_name
I believe you want something like below :)
You can get json path using the index .Whn I'm using rest-assured I always use something similar to below code to extract values from my json response .
Response response=given().contentType(ContentType.JSON).get("http://localhost:3000/posts");
JsonPath jsonPathEvaluator = response.jsonPath();
String fn1 = jsonPathEvaluator.get("firstName[0]");
String fn_1=jsonPathEvaluator.get("first_name[0]");
String fn2=jsonPathEvaluator.get("firstName[1]");
You can pass all pair to dict and then extract your values or if you need only values you can use set structure to store keys and separate list to values.

Resources