Mysql
 sql >> Database >  >> RDS >> Mysql

Nidifica in un modello Nest Json in una tabella SQL

puoi farlo in questo modo:

In [1]: fn = r'D:\temp\.data\40454898.json'

In [2]: with open(fn) as f:
   ...:     data = json.load(f)
   ...:

In [14]: t = pd.io.json.json_normalize(data['Volumes'],
    ...:                               ['Attachments','Tags'],
    ...:                               [['Attachments', 'VolumeId'],
    ...:                                ['Attachments', 'InstanceId']])
    ...:

In [15]: t
Out[15]:
         Key              Value Attachments.InstanceId   Attachments.VolumeId
0       Name  DBJanitor-Private    i-1234567890abcdef0  vol-049df61146c4d7901
1      Owner          DBJanitor    i-1234567890abcdef0  vol-049df61146c4d7901
2    Product           Database    i-1234567890abcdef0  vol-049df61146c4d7901
3  Portfolio         DB Janitor    i-1234567890abcdef0  vol-049df61146c4d7901
4    Service         DB Service    i-1234567890abcdef0  vol-049df61146c4d7901

NOTA:secondo argomento ['Attachments','Tags'] è un percorso verso il nostro record nidificato (data['Values']->Attachments->Tags ) e terzo argomento [['Attachments', 'VolumeId'], ['Attachments', 'InstanceId']] è un percorso ai metadati esterni (data['Values']->Attachments->VolumeId , data['Values']->Attachments->InstanceId )