What I am trying to do
- find all the files with the value corresponding to a certain word
- if true retrieve the filenames
- continue searching through 5000.json files
ex: pass through all the attributes: if ( trait_type is "background" and the value matches "none") & (trait_type is skin and the value matches "Nothing") & .....
Desired Outcome
name: #2
{
"trait_type": "Background",
"value": "none "
},
{
"trait_type": "Skin",
"value": "Nothing"
},
.
name: #5
{
"trait_type": "Background",
"value": "pink "
},
{
"trait_type": "Skin",
"value": "Nothing"
},
.
name: #8
{
"trait_type": "Background",
"value": "none"
},
{
"trait_type": "Skin",
"value": "Nothing"
},
.
Output: #2 #8
What I have
5000 .json files (the format is shown below) the only difference is the thing in the value
{
"name": "#1",
"description": " ",
"attributes": [
{
"trait_type": "Background",
"value": "pink "
},
{
"trait_type": "Mouth",
"value": "NoMouth"
},
{
"trait_type": "Clothing",
"value": "white shirt "
}
],
"custom_fields": {
}
}
The Code I have
import json
# load data using Python JSON module
with open('build/json/_metadata.json','r') as f:
data = json.loads(f.read())
# Flatten data
df_nested_list = pd.json_normalize(
data,
meta=['name'],
record_path =['attributes'])
df_nested_list