Jsonpath query nested objects - json

I've got this this json data that I want to look up a certain value from with a query:
http://pastebin.com/Vf59Cf9Q
I want to find description == "chassis" in this path:
$.entries..nestedStats.entries..nestedStats.entries.type
However, I just can't get it to work.
Tried these two alternatives, but no luck:
$.entries..nestedStats.entries..nestedStats.entries[?(#.type.description == 'chassis')]
$.entries..nestedStats.entries..nestedStats.entries.type[?(#.description == 'chassis')]
Have tried this on these sites:
http://jsonpath.com/
https://jsonpath.curiousconcept.com/
Any help would be appreciated!
/Patrik

This did the trick:
$.entries.*.nestedStats.entries.*.nestedStats.entries.type[?(# == "chassis")

Related

Jmeter Json Extractor with multiple conditional - failed

I am trying to create a Json Extractor and it`s being a thought activity. I have this json structure:
[
{
"reportType":{
"id":3,
"nomeTipoRelatorio":"etc etc etc",
"descricaoTipoRelatorio":"etc etc etc",
"esExibeSite":"S",
"esExibeEmail":"S",
"esExibeFisico":"N"
},
"account":{
"id":9999999,
"holdersName":"etc etc etc",
"accountNamber":"9999999",
"nickname":null
},
"file":{
"id":2913847,
"typeId":null,
"version":null,
"name":null,
"format":null,
"description":"description",
"typeCode":null,
"size":153196,
"mimeType":null,
"file":null,
"publicationDate":"2018-12-05",
"referenceStartDate":"2018-12-05",
"referenceEndDate":"2018-12-06",
"extension":null,
"fileStatusLog":{
"idArquivo":2913847,
"dhAlteracao":"2018-12-05",
"nmSistema":"SISTEMA X",
"idUsuario":999999,
"reportStatusIndicador":"Z"
}
}
}
]
What I need to do: First of all, I am using the option "Compute concatenation var" and "Match No." as -1. Because the service can bring in the response many of those.
I have to verify, if "reportStatusIndicador" = 'Z' or 'Y', if positive, I have to collect File.Id OR file.FileStatusLog.idArquivo, they are the same, I was trying the first option, in this case the number "2913847", but if come more results, I will collect all File.id`s
With this values in hands, I will continue with a for each for all File.id`s.
My last try, was this combination, after reading a lot and tried many others combinations.
[?(#...file.fileStatusLog.reportStatusIndicador == 'Z' || #...file.fileStatusLog.reportStatusIndicador == 'Y')].file.id
But my debug post processor always appears like this, empty:
filesIds=
Go for $..[?(#.file.fileStatusLog.reportStatusIndicador == 'Z' || #.file.fileStatusLog.reportStatusIndicador == 'Y')].file.id
Demo:
References:
Jayway JsonPath: Inline Predicates
JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios
I could do it with this pattern:
[?(#.file.fileStatusLog.reportStatusIndicador == 'Z' ||
#.file.fileStatusLog.reportStatusIndicador == 'Y')].file.id
filesIds_ALL=2913755,2913756,2913758,2913759,2913760,2913761,2913762,2913763,2913764,2913765,2913766,2913767,2913768,2913769,2913770

(Python)How to process complicated json data

//Please excuse my poor English.
Hello everyone, I am doing a project which is about a facebook comment spider.
then I find the Facebook Graph GUI. It will return a json file that's so complicated for me.
The json file is include so many parts
then I use json.loads to get all the json code
finally it return a dict for me.
and i dont know how to access the Value
for example i want get all the id or comment.
but i can only get the 2 key of dict "data" and "pading"
so, how can i get the next key? like "id" or "comment"
and how to process this complicated data.
code
Thank you very much.
Two ways I can think of, either you know what you're looking for and access it directly or you loop over the keys, look at the value of the keys and nest another loop until you reach the end of the tree.
You can do this using a self-calling function and with the appropriate usage of jQuery.
Here is an example:
function get_the_stuff(url)
{
$.getJSON(url, function ( data ) {
my_parser(data) });
}
function my_parser(node)
{
$.each(node, function(key, val) {
if ( val && typeof val == "object" ) { my_parser(val); }
else { console.log("key="+key+", val="+val); }
});
}
I omitted all the error checking. Also make sure the typeof check is appropriate. You might need some other elseif's to maybe treat numbers, strings, null or booleans in different ways. This is just an example.
EDIT: I might have slightly missed that the topic said "Python"... sorry. Feel free to translate to python, same principles apply.
EDIT2: Now lets' try in Python. I'm assuming your JSON is already imported into a variable.
def my_parser(node, depth=0):
if type(node) == "list":
for val in node:
my_parser(val,depth+1)
elif type(node) == "dict":
for key in node:
printf("level=%i key=%s" % ( depth, key ))
my_parser(node[key], depth+1)
elif type(node) == "str":
pritnf("level=%i value=%s" % ( depth, node ))
elsif type(node) == "int":
printf("level=%i value=%i % ( depth, node ))
else:
printf("level=%i value_unknown_type" % ( depth ))

How do I search for a specific string in a JSON Postgres data type column?

I have a column named params in a table named reports which contains JSON.
I need to find which rows contain the text 'authVar' anywhere in the JSON array. I don't know the path or level in which the text could appear.
I want to just search through the JSON with a standard like operator.
Something like:
SELECT * FROM reports
WHERE params LIKE '%authVar%'
I have searched and googled and read the Postgres docs. I don't understand the JSON data type very well, and figure I am missing something easy.
The JSON looks something like this.
[
{
"tileId":18811,
"Params":{
"data":[
{
"name":"Week Ending",
"color":"#27B5E1",
"report":"report1",
"locations":{
"c1":0,
"c2":0,
"r1":"authVar",
"r2":66
}
}
]
}
}
]
In Postgres 11 or earlier it is possible to recursively walk through an unknown json structure, but it would be rather complex and costly. I would propose the brute force method which should work well:
select *
from reports
where params::text like '%authVar%';
-- or
-- where params::text like '%"authVar"%';
-- if you are looking for the exact value
The query is very fast but may return unexpected extra rows in cases when the searched string is a part of one of the keys.
In Postgres 12+ the recursive searching in JSONB is pretty comfortable with the new feature of jsonpath.
Find a string value containing authVar:
select *
from reports
where jsonb_path_exists(params, '$.** ? (#.type() == "string" && # like_regex "authVar")')
The jsonpath:
$.** find any value at any level (recursive processing)
? where
#.type() == "string" value is string
&& and
# like_regex "authVar" value contains 'authVar'
Or find the exact value:
select *
from reports
where jsonb_path_exists(params, '$.** ? (# == "authVar")')
Read in the documentation:
The SQL/JSON Path Language
jsonpath Type

JMESPath JSON filter with multiple matches

I have a json block that looks a bit like this (have you guessed from AWS)
{ "Vpcs":[
{
"VpcId":"vpc-blabla1",
"OtherKey":"Value"
},
{
"VpcId":"vpc-blabla2",
"OtherKey":"Value"
},
{
"VpcId":"vpc-blabla3",
"OtherKey":"Value"
},
{
"VpcId":"vpc-blabla4",
"OtherKey":"Value"
}]
}
I want to use JMESPath to get the OtherKey value for vpc-blabla1 and vpc-blabla3 (Examples, could be any list of vpc-id)
I can get blabla1 with JMESpath filter
Vpcs[?VpcId=='blabla1'].OtherKey
But I can't find the syntax for multiple values? I have tried the Or syntax || and the composite syntax | but neither works? - See below for things I have tried.
Vpcs[?VpcId=='blabla1' || 'blabla1'].OtherKey
Vpcs[?VpcId=='blabla1' || ?VpcId=='blabla1'].OtherKey
Vpcs[(?VpcId=='blabla1') || (?VpcId=='blabla1')].OtherKey
Vpcs[?VpcId=='blabla1' | ?VpcId=='blabla1'].OtherKey
Any suggestions? Is this possible or am I going to have to gather one result set at a time and recombine the results I want?
The general syntax for multiple is [? expr1 || expr2] so in your case, you can use:
Vpcs[?VpcId=='vpc-blabla1' || VpcId=='vpc-blabla2'].OtherKey
Another option, if you have many VPC ids you're search for, you can also say:
Vpcs[?contains(`["vpc-blabla1", "vpc-blabla2"]`, VpcId)].OtherKey

How can I groupBy and change content of the value in couchbase?

Exple :
I have a result like this
Result1 AFTER EMIT:
Key-------------------------------value
"2014/10/31" ----------------- {"A":a}
"2014/10/31" ----------------- {"B":b}
"2014/10/31"----------------- {"C":c}
"2014/10/31"----------------- {"D":d}
How can I output this new result from the previous one:
Key-------------------------value
"2014/10/31" -----------------{"Array":["A":a, "B":b, "C":c, "D":d]}
Is there a way? Any help will be appreciated. Thanks
You can use Couchbase v3 new N1QL query language for that. Also there is Query Language Tutorial. Specifically Array Comprehensions syntax.
I found it . Just do : group = true in the path or select it from the filter result .
and a reduce function to return all the values from the map. also you can add the start key = "2014/10/31" and end key= "2014/10/31".