Skip to content

Instantly share code, notes, and snippets.

@iHaikal
Created October 12, 2021 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iHaikal/18685d2274bba1372765fa81c4ea7495 to your computer and use it in GitHub Desktop.
Save iHaikal/18685d2274bba1372765fa81c4ea7495 to your computer and use it in GitHub Desktop.
Regular JSON to dotted
import json
with open('test_dictionary_regular.json') as f:
data = json.load(f)
with open('test_dictionary_dot.json') as f:
test = json.load(f)
def to_dot(data: dict) -> dict:
out = {}
for key, value in data.items():
if type(value) == dict:
child = to_dot(value)
for k, v in child.items():
out[f'{key}.{k}'] = v
else:
out[key] = value
return out
to_dot(data) == test
{
"re.primStrat": "Real Estate Value Added",
"re.otherStrats": ["Value Added"],
"re.mainPropType": "Residential",
"re.propTypes": [{
"id": 16232,
"text": "Multi-family"
}
],
"re.debtTypes": [],
"geoFocus.coreLocations": "North America",
"geoFocus.mainFundFocus": "North America",
"geoFocus.geoExposure": [{
"id": 95,
"text": "US"
}, {
"id": 1,
"text": "North America"
}
],
"targReturns.net.min": 13,
"targReturns.net.max": 15,
"targReturns.gross.min": 16,
"targReturns.gross.max": 18,
"indusFocus.coreIndus": "Real Estate",
"indusFocus.verticals": "",
"indusFocus.indus": ["Commercial Property", "Real Estate"],
"serviceProvs.placementAgents": [{
"id": -1,
"text": "Not Used"
}
],
"serviceProvs.lawFirms": [{
"id": 12374,
"text": "AB Law"
}
],
"serviceProvs.admins": [{
"id": 54795,
"text": "Abc Admin"
}
],
"serviceProvs.auditors": [{
"id": 58627,
"text": "Audit LLP"
}
],
"serviceProvs.custodians": null,
"basic.manager.id": 53210,
"basic.manager.name": "ABC Partners Capital Group",
"basic.manager.headquarterAddress.country": "US",
"basic.manager.headquarterAddress.region": "North America",
"basic.manager.headquarterAddress.line": "10 Partners Avenue",
"basic.manager.headquarterAddress.city": "New York",
"basic.manager.headquarterAddress.state": "NY",
"basic.manager.headquarterAddress.postcode": "10010",
"basic.manager.headquarterAddress.website": "http://www.abcpartnerscapitalgroup.com/",
"basic.manager.headquarterAddress.email": null,
"basic.manager.headquarterAddress.telephone": "+1 212 874 5420",
"basic.manager.headquarterAddress.fax": "+1 815 412 8567",
"basic.strategy": "Real Estate Value Added",
"fundRaising.status": "Closed",
"fundRaising.fundSize.usd": 874.3,
"fundRaising.finalClose.date": "2016-07-24",
"fundRaising.finalClose.size.usd": 874.3,
"fundRaising.finalClose.size.local": 874.3,
"fundRaising.finalClose.size.eur": 524.84,
"fundRaising.currency": "USD",
"fundRaising.targetSize.local": 653.5,
"fundRaising.targetSize.usd": 653.5,
"fundRaising.targetSize.eur": 500.09,
"fundRaising.launched.date": "2015-03-01",
"fundRaising.coInvCapAmnt.local": null,
"fundRaising.coInvCapAmnt.usd": null,
"fundRaising.coInvCapAmnt.eur": null,
"privateCap.vintage": 2016,
"privateCap.overallFunds": 5,
"privateCap.seriesFunds": 4,
"privateCap.single": false,
"privateCap.creditFacil": "Yes",
"name": "ABC Partners IV",
"addressDetails.secondaryLocations": ["Houston,TX,US",
"San Francisco,CA,US",
"Stamford,CT,US"],
"addressDetails.email": null,
"addressDetails.region": "North America",
"fundTerm.annualMangFee.fee": 1.5,
"fundTerm.mangFeeFrequency.frequency": "Quarterly",
"pe.buyoutFundSize": null,
"pe.buyoutFundLeverage": null,
"pe.investmentSizePerPortfolioCompany.min": 5,
"pe.investmentSizePerPortfolioCompany.max": 25,
"structure.structureType": "Commingled",
"structure.domicile": "Delaware",
"structure.legalStructure": "Limited Partnership",
"createdOn": "2018-03-08",
"id": "f73809rkj31",
"inceptionDate": null
}
{
"re": {
"primStrat": "Real Estate Value Added",
"otherStrats": ["Value Added"],
"mainPropType": "Residential",
"propTypes": [{
"id": 16232,
"text": "Multi-family"
}],
"debtTypes": []
},
"geoFocus": {
"coreLocations": "North America",
"mainFundFocus": "North America",
"geoExposure": [{
"id": 95,
"text": "US"
}, {
"id": 1,
"text": "North America"
}]
},
"targReturns": {
"net": {
"min": 13,
"max": 15
},
"gross": {
"min": 16,
"max": 18
}
},
"indusFocus": {
"coreIndus": "Real Estate",
"verticals": "",
"indus": ["Commercial Property", "Real Estate"]
},
"serviceProvs": {
"placementAgents": [{
"id": -1,
"text": "Not Used"
}],
"lawFirms": [{
"id": 12374,
"text": "AB Law"
}],
"admins": [{
"id": 54795,
"text": "Abc Admin"
}],
"auditors": [{
"id": 58627,
"text": "Audit LLP"
}],
"custodians": null
},
"basic": {
"manager": {
"id": 53210,
"name": "ABC Partners Capital Group",
"headquarterAddress": {
"country": "US",
"region": "North America",
"line": "10 Partners Avenue",
"city": "New York",
"state": "NY",
"postcode": "10010",
"website": "http://www.abcpartnerscapitalgroup.com/",
"email": null,
"telephone": "+1 212 874 5420",
"fax": "+1 815 412 8567"
}
},
"strategy": "Real Estate Value Added"
},
"fundRaising": {
"status": "Closed",
"fundSize": {
"usd": 874.3
},
"finalClose": {
"date": "2016-07-24",
"size": {
"usd": 874.3,
"local": 874.3,
"eur": 524.84
}
},
"currency": "USD",
"targetSize": {
"local": 653.5,
"usd": 653.5,
"eur": 500.09
},
"launched": {
"date": "2015-03-01"
},
"coInvCapAmnt": {
"local": null,
"usd": null,
"eur": null
}
},
"privateCap": {
"vintage": 2016,
"overallFunds": 5,
"seriesFunds": 4,
"single": false,
"creditFacil": "Yes"
},
"name": "ABC Partners IV",
"addressDetails": {
"secondaryLocations": ["Houston,TX,US", "San Francisco,CA,US", "Stamford,CT,US"],
"email": null,
"region": "North America"
},
"fundTerm": {
"annualMangFee": {
"fee": 1.5
},
"mangFeeFrequency": {
"frequency": "Quarterly"
}
},
"pe": {
"buyoutFundSize": null,
"buyoutFundLeverage": null,
"investmentSizePerPortfolioCompany": {
"min": 5,
"max": 25
}
},
"structure": {
"structureType": "Commingled",
"domicile": "Delaware",
"legalStructure": "Limited Partnership"
},
"createdOn": "2018-03-08",
"id": "f73809rkj31",
"inceptionDate": null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment