M
M
Mpyrulearn2020-08-30 18:02:57
MySQL
Mpyrulearn, 2020-08-30 18:02:57

How to load data into MySQL from JSON file with variable data structure?

There is a file (json-export of a chat from Telegram), which has a variable structure,

example:
[
  {
   "id": 5,
   "type": "message",
   "date": "2019-01-02T12:05:43",
   "from": "nik",
   "from_id": 12457887,
   "text": "hi!"
  },
  {
   "id": 6,
   "type": "message",
   "date": "2019-01-02T12:05:45",
   "from": "nik2",
   "from_id": 22457877,
   "text": [
    "hi tyt info!",
    {
     "type": "link",
     "text": "https://telegra.ph/film-05-01"
    },
    ""
   ]
  }
]


Is it possible to upload this file to a MySQL database, similar to CSV?
Or will you have to manually parse the file and load it with the script manually?
And what format would be better to choose for storing the "text" field for the case when it is a list with dictionaries inside (VARCHAR, TEXT)?
' [
    "hi tyt info!",
    {
     "type": "link",
     "text": "https://telegra.ph/film-05-01"
    },
    ""
   ]'

Task: to be able to process chat logs using the MySQL database, selections, text search, statistics, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2020-08-30
@2ord

In addition to the "text" field, which has some strange structure, the
rest can be distributed into columns.
If text is a string, then it is better to put it into an array right away. Then just a JSON column type.

Is it possible to upload this file to a MySQL database, similar to CSV?
In my opinion, no regular utility.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question