Answer the question
In order to leave comments, you need to log in
How to find and take the necessary data from json?
There is a group of files with the following content:
{
"responseHeader": {
"zkConnected": true,
"status": 0,
"QTime": 394,
"params": {
"q": "+2019 +BUICK +ENCLAVE",
"defType": "edismax",
"qf": "title_en^200.0 title_es^200 title_ar^200 title_pt^200 title_ru^200 title_th^200 title_fr^200 title_ko^200 category_translated^150.0 category_translated_path^120.0 category_key_path^90.0 mmy^80.0 category_key^75",
"fl": "imdocid,imcontent_text_id,path,title_ordered,category_key,file_type",
"fq": [
"channel:MANUALS",
"file_type:application/pdf",
" -(usergroup_key:[* TO *] OR -usergroup_key:PUBLIC)",
" -(view_key:[* TO *] OR -view_key:PUBLIC)"
],
"rows": "15",
"_forwardedCount": "1",
"stopwords": "true",
"useParams": "default"
}
},
"response": {
"numFound": 3,
"start": 0,
"numFoundExact": true,
"docs": [
{
"imdocid": "MA4840",
"path": "/resources/sites/GMA/content/staging/MANUALS/4000/MA4840/en_US/7.0/GTK_2019_Buick_Enclave_84149417_A.pdf",
"file_type": "application/pdf",
"category_key": [
"QUICK_REFERENCE_MANUALS_BROWSE",
"BUICK",
"ENCLAVE",
"2019",
"BUICK_INTELLILINK"
],
"imcontent_text_id": "863d13356ad04f409b0d2b36061e63b1",
"title_ordered": "Getting to Know Your 2019 Buick Enclave"
},
{
"imdocid": "MA4284",
"path": "/resources/sites/GMA/content/staging/MANUALS/4000/MA4284/en_US/2.0/19_BUI_Enclave_OM_en_US_U_84149412B_2018SEP12_2P.pdf",
"file_type": "application/pdf",
"category_key": [
"OWNERS_MANUALS_BROWSE",
"BUICK",
"ENCLAVE",
"2019"
],
"imcontent_text_id": "b0640df8bc194096b65babf09543de11",
"title_ordered": "2019 Buick Enclave Owner Manual"
},
{
"imdocid": "MA4119",
"path": "/resources/sites/GMA/content/staging/MANUALS/4000/MA4119/en_US/2.0/19_BUI_IM_en_US_U_84134605B_2018JUL03_2P.pdf",
"file_type": "application/pdf",
"category_key": [
"INFOTAINMENT_MANUALS_BROWSE",
"BUICK",
"ENCLAVE",
"REGAL",
"ENVISION",
"ENCORE",
"2019",
"BUICK_INTELLILINK"
],
"imcontent_text_id": "09139b09b5004fe78bf59b574a8cb096",
"title_ordered": "2019 Buick Infotainment System Manual"
}
]
}
}
Answer the question
In order to leave comments, you need to log in
A classic example for solving by recursion.
Recurse through the entire structure, iterating over the keys or elements of the list. If you meet a category_key at the same nesting level, then remember the path from the same nesting level, if you meet an element of the dict or list type, then you call yourself with the transfer of this element.
Well, select the desired category_key in the list of which will be OWNERS_MANUALS
What does different nesting mean?
Show what monsters are obtained and what exactly is the problem? The task is trivial: to loop through the list, check the condition and return the results through yeld, or combine them into a collection.
It’s worth it if there is less code and it will be clearer, the current is some kind of refactoring and not optimization)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question