I am trying to break this JSON file into two parts
1st Part: The Header Part which contains all the information present before "line:10" or "in_network" Key
2nd Part: The detail Part which contains all the information present inside the key "in_network"
Here is what JSON file looks like
{
"reporting_entity_name": "launcher",
"reporting_entity_type": "launcher",
"plan_name": "launched",
"plan_id_type": "hios",
"plan_id": "1111111111",
"plan_market_type": "individual",
"last_updated_on": "2020-08-27",
"version": "1.0.0",
"in_network": [
{
"negotiation_arrangement": "ffs",
"name": "Boosters",
"billing_code_type": "CPT",
"billing_code_type_version": "2020",
"billing_code": "27447",
"description": "Boosters On Demand",
"negotiated_rates": [
{
"provider_groups": [
{
"npi": [
0
],
"tin": {
"type": "ein",
"value": "11-1111111"
}
}
],
"negotiated_prices": [
{
"negotiated_type": "negotiated",
"negotiated_rate": 123.45,
"expiration_date": "2022-01-01",
"billing_class": "organizational"
}
]
}
]
}
]
}
Here is my python code which i am trying to use to this operation:
flag = 0
file = open('new_test.JSON', 'r')
detail_file_1 = open('new_test_detail.json', 'a')
detail_file_1.write('{')
detail_file_1.close()
for line in file:
if flag == 0:
if line != ' "in_network": [':
header_file = open('new_test_header.json', 'a')
header_file.write(line)
header_file.close()
else:
flag = 1
else:
detail_file = open('new_test_detail.json', 'a')
detail_file.write(line)
detail_file.close()
header_file_1 = open('new_test_header.json', 'a')
header_file_1.write('}')
header_file_1.close()
Here is what i expected 1st part file should look like:
{
"reporting_entity_name": "launcher",
"reporting_entity_type": "launcher",
"plan_name": "launched",
"plan_id_type": "hios",
"plan_id": "1111111111",
"plan_market_type": "individual",
"last_updated_on": "2020-08-27",
"version": "1.0.0",
}
Here is what i expected 2nd part file should look like:
"in_network": [
{
"negotiation_arrangement": "ffs",
"name": "Boosters",
"billing_code_type": "CPT",
"billing_code_type_version": "2020",
"billing_code": "27447",
"description": "Boosters On Demand",
"negotiated_rates": [
{
"provider_groups": [
{
"npi": [
0
],
"tin": {
"type": "ein",
"value": "11-1111111"
}
}
],
"negotiated_prices": [
{
"negotiated_type": "negotiated",
"negotiated_rate": 123.45,
"expiration_date": "2022-01-01",
"billing_class": "organizational"
}
]
}
]
}
]
}
But Unfortunately my code fails to do so. Can some help me with this.
What python code changes is needed to do so.