I have a JSON of the following structure:
{
    "a": "a_1",
    "b": "b_1",
    "c": [{
        "d": "d_1",
        "e": "e_1",
        "f": [],
        "g": "g_1",
        "h": "h_1"
    }, {
        "d": "d_2",
        "e": "e_2",
        "f": [],
        "g": "g_2",
        "h": "h_2"
    }, {
        "d": "d_3",
        "e": "e_3",
        "f": [{
            "i": "i_1",
            "j": "j_1",
            "k": "k_1",
            "l": "l_1",
            "m": []
        }, {
            "i": "i_2",
            "j": "j_2",
            "k": "k_2",
            "l": "l_2",
            "m": [{
                "n": "n_1",
                "o": "o_1",
                "p": "p_1",
                "q": "q_1"
            }]
        }],
        "g": "g_3",
        "h": "h_3"
    }]
}
And I want to convert it into pandas data frame of the following type:
How can I achieve that?
Following is my attempt but the direction is completely diff.
code:
from pandas.io.json import json_normalize
def flatten_json(y):
    out = {}
    def flatten(x, name=''):
        if type(x) is dict:
            for a in x:
                flatten(x[a], name + a + '_')
        elif type(x) is list:
            i = 0
            for a in x:
                flatten(a, name + str(i) + '_')
                i += 1
        else:
            out[name[:-1]] = x
    flatten(y)
    return out
sample_object = { "a": "a_1", "b": "b_1", "c": [{ "d": "d_1", "e": "e_1", "f": [], "g": "g_1", "h": "h_1" }, { "d": "d_2", "e": "e_2", "f": [], "g": "g_2", "h": "h_2" }, { "d": "d_3", "e": "e_3", "f": [{ "i": "i_1", "j": "j_1", "k": "k_1", "l": "l_1", "m": [] }, { "i": "i_2", "j": "j_2", "k": "k_2", "l": "l_2", "m": [{ "n": "n_1", "o": "o_1", "p": "p_1", "q": "q_1" }] }], "g": "g_3", "h": "h_3" }] }
intermediate_json = flatten_json(sample_object)
flattened_df = json_normalize(intermediate_json)
transposed_df = flattened_df.T
print(transposed_df.to_string())
OUTPUT:
                 0
a              a_1
b              b_1
c_0_d          d_1
c_0_e          e_1
c_0_g          g_1
c_0_h          h_1
c_1_d          d_2
c_1_e          e_2
c_1_g          g_2
c_1_h          h_2
c_2_d          d_3
c_2_e          e_3
c_2_f_0_i      i_1
c_2_f_0_j      j_1
c_2_f_0_k      k_1
c_2_f_0_l      l_1
c_2_f_1_i      i_2
c_2_f_1_j      j_2
c_2_f_1_k      k_2
c_2_f_1_l      l_2
c_2_f_1_m_0_n  n_1
c_2_f_1_m_0_o  o_1
c_2_f_1_m_0_p  p_1
c_2_f_1_m_0_q  q_1
c_2_g          g_3
c_2_h          h_3

 
    