# \[SOLVED\] Extracting Nested data from JSON files using python

**URL:** <https://onehack.st/t/solved-extracting-nested-data-from-json-files-using-python/74029>\
**Category:** Tutorials & Methods\
**Tags:** solved, programming, tips-tricks\
**Created:** [March 19, 2020, 1:48pm UTC](https://onehack.st/t/solved-extracting-nested-data-from-json-files-using-python/74029 "2020-03-19T13:48:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aj\_senpai](https://onehack.st/user_avatar/onehack.st/aj_senpai/32/29680_2.png) [@Aj\_senpai](https://onehack.st/u/Aj_senpai)\
**Post date:** [March 19, 2020, 1:48pm UTC](https://onehack.st/t/solved-extracting-nested-data-from-json-files-using-python/74029/1 "2020-03-19T13:48:00Z")

</div>

i have never worked with json files in python before .. and i need to extract some data from around 1000 json files . can anyone help me?

sample data:

“data”:{  
“attributes”:{  
**“productnumber”** :{  
“values”:[  
{  
“source”:“internal”,  
“locale”:“en-US”,  
**“value”:“04019669”**  
}

i need to extract productnumber value from all these json files and move it to some other file. initially i thought of using regex but that’s not an optimize solution. if anyone of you know something better to extract these information other than python let me know.

---

<div class="post-metadata">

**Author:** ![dydx](https://onehack.st/user_avatar/onehack.st/dydx/32/36729_2.png) [@dydx](https://onehack.st/u/dydx)\
**Post date:** [March 19, 2020, 2:07pm UTC](https://onehack.st/t/solved-extracting-nested-data-from-json-files-using-python/74029/2 "2020-03-19T14:07:24Z")

</div>

can you upload json file

---

<div class="post-metadata">

**Author:** ![Aj\_senpai](https://onehack.st/user_avatar/onehack.st/aj_senpai/32/29680_2.png) [@Aj\_senpai](https://onehack.st/u/Aj_senpai)\
**Post date:** [March 19, 2020, 2:30pm UTC](https://onehack.st/t/solved-extracting-nested-data-from-json-files-using-python/74029/3 "2020-03-19T14:30:59Z")

</div>

Data is confidential bro.. can’t upload it. This is not a personal project.  
Moreover you got the point what i am trying to do with jason files

---

<div class="post-metadata">

**Author:** ![Prometheus](https://onehack.st/user_avatar/onehack.st/prometheus/32/34950_2.png) [@Prometheus](https://onehack.st/u/Prometheus)\
**Post date:** [March 20, 2020, 2:34pm UTC](https://onehack.st/t/solved-extracting-nested-data-from-json-files-using-python/74029/4 "2020-03-20T14:34:29Z")

</div>

Please read the FAQ, Deep coding questions are not allowed! 🙁

- [#FAQ - Everything You Need to Know](https://onehack.st/t/faq-guidelines/5#what-kind-of-%E2%80%9Chelp%E2%80%9D-queries-are-not-allowed)

> - How to code this, can you help me with a coding script? I am stuck with a code, now what to do? \<\<\< Please, avoid asking such deep programming language questions, as there is already a website dedicated for this **stackoverflow**! 🙁

**Anyways** , You can use regular expressions to isolate those JSON objects you are interested in from your available files. Here is [a relevant discussion](https://stackoverflow.com/questions/2583472/regex-to-validate-json). & also check the below thread! 🙂

> <https://stackoverflow.com/questions/38029421/recursive-walk-through-a-json-file-extracting-selected-strings>

---

<div class="post-metadata">

**Author:** ![Aj\_senpai](https://onehack.st/user_avatar/onehack.st/aj_senpai/32/29680_2.png) [@Aj\_senpai](https://onehack.st/u/Aj_senpai)\
**Post date:** [March 20, 2020, 6:22pm UTC](https://onehack.st/t/solved-extracting-nested-data-from-json-files-using-python/74029/5 "2020-03-20T18:22:32Z")

</div>

I did not know about it. I’ll remember next time. Thanks (:

---

<div class="post-metadata">

**Author:** ![Darklooter](https://onehack.st/user_avatar/onehack.st/darklooter/32/1882_2.png) [@Darklooter](https://onehack.st/u/Darklooter)\
**Post date:** [March 22, 2020, 6:52am UTC](https://onehack.st/t/solved-extracting-nested-data-from-json-files-using-python/74029/6 "2020-03-22T06:52:19Z")

</div>

I am late but.. if you will notice the json  
data”:{  
“attributes”:{  
**“productnumber”** :{  
“values”:[  
{  
“source”:“internal”,  
“locale”:“en-US”,  
**“value”:“04019669”**  
}

It’s just a dictionary under a dictionary so  
You can try something like  
Print(Data[“attributes”] )  
It will return a dictionary of product number and values key value dictionary.
