Nested JSON Flattener
Transform a deeply nested JSON structure into a flattened key-value format where each path is represented by dot notation
Start file
{
"company": {
"details": {
"name": "TechCorp",
"founded": 1995,
"isPublic": true
},
"locations": {
"headquarters": {
"address": {
"street": "123 Innovation Way",
"unit": "4B",
"city": "San Francisco",
"state": "CA",
"zip": "94105"
},
"coordinates": {
"lat": 37.7749,
"lng": -122.4194
}
},
"branches": {
"europe": {
"primary": {
"city": "London",
"employees": 250,
"opened": "2020-01-15"
},
"secondary": {
"city": "Berlin",
"employees": 120,
"opened": "2021-03-01"
}
},
"asia": {
"primary": {
"city": "Tokyo",
"employees": 180,
"opened": "2019-11-30"
}
}
}
},
"metrics": {
"financial": {
"revenue": {
"2021": 1500000,
"2022": 2200000,
"2023": 3100000
},
"expenses": {
"2021": 1200000,
"2022": 1800000,
"2023": 2500000
}
},
"performance": {
"goals": {
"q1": 85,
"q2": 90,
"q3": 88,
"q4": 92
}
}
}
}
}
End file
company.details.name=TechCorp
company.details.founded=1995
company.details.isPublic=true
company.locations.headquarters.address.street=123 Innovation Way
company.locations.headquarters.address.unit=4B
company.locations.headquarters.address.city=San Francisco
company.locations.headquarters.address.state=CA
company.locations.headquarters.address.zip=94105
company.locations.headquarters.coordinates.lat=37.7749
company.locations.headquarters.coordinates.lng=-122.4194
company.locations.branches.europe.primary.city=London
company.locations.branches.europe.primary.employees=250
company.locations.branches.europe.primary.opened=2020-01-15
company.locations.branches.europe.secondary.city=Berlin
company.locations.branches.europe.secondary.employees=120
company.locations.branches.europe.secondary.opened=2021-03-01
company.locations.branches.asia.primary.city=Tokyo
company.locations.branches.asia.primary.employees=180
company.locations.branches.asia.primary.opened=2019-11-30
company.metrics.financial.revenue.2021=1500000
company.metrics.financial.revenue.2022=2200000
company.metrics.financial.revenue.2023=3100000
company.metrics.financial.expenses.2021=1200000
company.metrics.financial.expenses.2022=1800000
company.metrics.financial.expenses.2023=2500000
company.metrics.performance.goals.q1=85
company.metrics.performance.goals.q2=90
company.metrics.performance.goals.q3=88
company.metrics.performance.goals.q4=92
View Diff
1,67c1,29
< {
< "company": {
< "details": {
< "name": "TechCorp",
< "founded": 1995,
< "isPublic": true
< },
< "locations": {
< "headquarters": {
< "address": {
< "street": "123 Innovation Way",
< "unit": "4B",
< "city": "San Francisco",
< "state": "CA",
< "zip": "94105"
< },
< "coordinates": {
< "lat": 37.7749,
< "lng": -122.4194
< }
< },
< "branches": {
< "europe": {
< "primary": {
< "city": "London",
< "employees": 250,
< "opened": "2020-01-15"
< },
< "secondary": {
< "city": "Berlin",
< "employees": 120,
< "opened": "2021-03-01"
< }
< },
< "asia": {
< "primary": {
< "city": "Tokyo",
< "employees": 180,
< "opened": "2019-11-30"
< }
< }
< }
< },
< "metrics": {
< "financial": {
< "revenue": {
< "2021": 1500000,
< "2022": 2200000,
< "2023": 3100000
< },
< "expenses": {
< "2021": 1200000,
< "2022": 1800000,
< "2023": 2500000
< }
< },
< "performance": {
< "goals": {
< "q1": 85,
< "q2": 90,
< "q3": 88,
< "q4": 92
< }
< }
< }
< }
< }
---
> company.details.name=TechCorp
> company.details.founded=1995
> company.details.isPublic=true
> company.locations.headquarters.address.street=123 Innovation Way
> company.locations.headquarters.address.unit=4B
> company.locations.headquarters.address.city=San Francisco
> company.locations.headquarters.address.state=CA
> company.locations.headquarters.address.zip=94105
> company.locations.headquarters.coordinates.lat=37.7749
> company.locations.headquarters.coordinates.lng=-122.4194
> company.locations.branches.europe.primary.city=London
> company.locations.branches.europe.primary.employees=250
> company.locations.branches.europe.primary.opened=2020-01-15
> company.locations.branches.europe.secondary.city=Berlin
> company.locations.branches.europe.secondary.employees=120
> company.locations.branches.europe.secondary.opened=2021-03-01
> company.locations.branches.asia.primary.city=Tokyo
> company.locations.branches.asia.primary.employees=180
> company.locations.branches.asia.primary.opened=2019-11-30
> company.metrics.financial.revenue.2021=1500000
> company.metrics.financial.revenue.2022=2200000
> company.metrics.financial.revenue.2023=3100000
> company.metrics.financial.expenses.2021=1200000
> company.metrics.financial.expenses.2022=1800000
> company.metrics.financial.expenses.2023=2500000
> company.metrics.performance.goals.q1=85
> company.metrics.performance.goals.q2=90
> company.metrics.performance.goals.q3=88
> company.metrics.performance.goals.q4=92
Solutions
The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!
Check out these helpful resources to improve your Vim skills... Game on.
Unlock 13 remaining solutions by signing in and submitting your own entry
#14 Heitor Dantas / @heitordnts - Score: 161 - 12/18/24 @ 02:09
:%s/"//g<CR>:<Esc>gg=%jjqq0wdiWj<C-V>/}<CR>kpdi{Vkpq:8<CR>@q:13<CR>@@:187<BS><CR>@@3j@@5j@@:34<CR>@@3j@@5j@@k@@8k@@k@@7k@@8k@@k@@:7<CR>@@k@@ggj@@di{Vkp:.,$<<CR>:%s/: /=<CR>:<Up><Left><Left><Right><Right><BS><BS><BS>/./g<CR>:<Up><Left><Left><BS><Left><BS>,<CR>:wq<CR>
0 comments