M
M
mr jeery2018-02-08 03:00:21
JavaScript
mr jeery, 2018-02-08 03:00:21

How to load huge json api via pagination?

There is an API for almost all cities in the world in .json format.

[
  {
    "id": 707860,
    "name": "Hurzuf",
    "country": "UA",
    "coord": {
      "lon": 34.283333,
      "lat": 44.549999
    }
  },
  {
    "id": 519188,
    "name": "Novinki",
    "country": "RU",
    "coord": {
      "lon": 37.666668,
      "lat": 55.683334
    } 
},
....
]

Previously, I set up a one-time upload, because there was not much data.
But this will not work here, you need to make a request to the following data, only when you click on the load of a new city page.
How to do it?
Can you share an example of such an implementation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Ainur Valiev, 2018-02-08
@vaajnur

divide json into chunks and display in pagination

I
Interface, 2018-02-09
@Interface

If the file is not very large (up to tens of megabytes) - you can read it into memory, you get a regular array, you can give it to the usual slice.
If the file is very large (hundreds of megabytes or more) - I think the best thing would be to read it through some lib like https://github.com/dominictarr/JSONStream and put it in the database. And contact her.
Please note that the file may not fit in RAM - then you need to do it in a threaded manner (and not only then).
Those. do not read the whole file piece by piece -> glue -> put it in the database,
but read the piece -> put the piece in the database (and make sure that the memory does not leak)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question