I referenced this answer question,
My Sample Data
$personData = @'
{
"persons": [{
"johndoe": [{
"id": "4334234 <>",
"family_adress": {
"mother": "address of family",
"father": "",
"brother": "address of family"
},
"childiren": {
"first": 1024,
"second":128
},
"years_activity": {
"2021": [ "sample entry-1", "sample entry-2" ],
"2022": [ "sample entry-1", "sample entry-2" ]
}
}],
"johndoe2": [{
"id": "4334234 <>",
"family_adress": {
"mother": "address of family...",
"father": "",
"brother": "...address of family"
},
"childiren": {
"first": 25,
"second": 12
},
"years_activity": {
"2021": [ "sample entry-4", "sample entry-r" ],
"2022": [ "sample entry-5", "sample entry-s" ]
}
}]
}]
}
'@ | ConvertFrom-Json
My Output:
NamePath Value
-------- -----
persons[0].johndoe[0].id 4334234 <>
persons[0].johndoe[0].family_adress.mother address of family
persons[0].johndoe[0].family_adress.father
persons[0].johndoe[0].family_adress.brother address of family
persons[0].johndoe[0].childiren.first 1024
persons[0].johndoe[0].childiren.second 128
persons[0].johndoe[0].years_activity.2021[0] sample entry-1
persons[0].johndoe[0].years_activity.2021[1] sample entry-2
persons[0].johndoe[0].years_activity.2022[0] sample entry-1
persons[0].johndoe[0].years_activity.2022[1] sample entry-2
persons[0].johndoe2[0].id 4334234 <>
persons[0].johndoe2[0].family_adress.mother address of family...
persons[0].johndoe2[0].family_adress.father
persons[0].johndoe2[0].family_adress.brother ...address of family
persons[0].johndoe2[0].childiren.first 25
persons[0].johndoe2[0].childiren.second 12
persons[0].johndoe2[0].years_activity.2021[0] sample entry-4
persons[0].johndoe2[0].years_activity.2021[1] sample entry-r
persons[0].johndoe2[0].years_activity.2022[0] sample entry-5
persons[0].johndoe2[0].years_activity.2022[1] sample entry-s
- I want to access this NamePaths with CSV.
Headers: id family_address childrens years_activitys // My Rows: JohnDoe, JohnDoe2
- After CSV I want to access pritn all propertiesx,
foreach (person in CSV) {
id:
family_address:
childrens:
years_activitys: (if header equal to SubArray also print them separately)
}
- Also can I access these values with structed format like
foreach (activities in person.$username.years_activitys ) { key : value }
I'm trying to do exactly something like this, thanks in advance for your help.