Repository: modin-project/modin

Issue:
`read_json` defines metadata incorrectly
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Ubuntu 20.04
- **Modin version**: bded2e968a0057b1d448aec1957986fdc650d906
- **Python version**: 3.8.10
- **Code we can use to reproduce**:
```
import pandas
import numpy as np
import os

import modin.pandas as pd
from modin.config import NPartitions
NPartitions.put(4)

filename = "test_json.json"
row_size = 256
col_size = 80

try:
    df = pandas.DataFrame(
        {f"col{x}": np.arange(row_size) for x in range(col_size)}
    )
    df.to_json(filename, lines=True, orient="records")

    df_pd = pd.read_json(filename, lines=True, orient="records")
    parts_width_cached = df_pd._query_compiler._modin_frame._column_widths_cache
    num_splits = len(df_pd._query_compiler._modin_frame._partitions[0])
    parts_width = [len(df_pd._query_compiler._modin_frame._partitions[0][i].get().columns) for i in range(num_splits)]

    print(parts_width_cached, parts_width) # [32, 32, 32, -16] [32, 32, 16, 0]

finally:
    os.remove(filename)
```

<!--
You can obtain the Modin version with

python -c "import modin; print(modin.__version__)"
-->

### Describe the problem
<!-- Describe the problem clearly here. -->

### Source code / logs
<!-- Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem. -->



Discussion:

Resolving patch:
diff --git a/modin/engines/base/io/text/json_dispatcher.py b/modin/engines/base/io/text/json_dispatcher.py
--- a/modin/engines/base/io/text/json_dispatcher.py
+++ b/modin/engines/base/io/text/json_dispatcher.py
@@ -75,12 +75,15 @@ def _read(cls, path_or_buf, **kwargs):
                 column_widths = [len(columns)]
                 num_splits = 1
             else:
-                column_widths = [
-                    column_chunksize
-                    if i != num_splits - 1
-                    else len(columns) - (column_chunksize * (num_splits - 1))
-                    for i in range(num_splits)
-                ]
+                column_widths = []
+                for i in range(num_splits):
+                    if len(columns) > (column_chunksize * i):
+                        if len(columns) > (column_chunksize * (i + 1)):
+                            column_widths.append(column_chunksize)
+                        else:
+                            column_widths.append(len(columns) - (column_chunksize * i))
+                    else:
+                        column_widths.append(0)
 
             args = {"fname": path_or_buf, "num_splits": num_splits, **kwargs}
 


Test patch:
diff --git a/modin/pandas/test/test_io.py b/modin/pandas/test/test_io.py
--- a/modin/pandas/test/test_io.py
+++ b/modin/pandas/test/test_io.py
@@ -92,12 +92,12 @@ def setup_json_file(filename, row_size=NROWS, force=True):
         df.to_json(filename)
 
 
-def setup_json_lines_file(filename, row_size=NROWS, force=True):
+def setup_json_lines_file(filename, row_size=NROWS, col_size=2, force=True):
     if os.path.exists(filename) and not force:
         pass
     else:
         df = pandas.DataFrame(
-            {"col1": np.arange(row_size), "col2": np.arange(row_size)}
+            {f"col{x + 1}": np.arange(row_size) for x in range(col_size)}
         )
         df.to_json(filename, lines=True, orient="records")
 
@@ -1355,6 +1355,26 @@ def test_read_json_file_handle(self, request, read_mode):
         finally:
             teardown_test_files([unique_filename])
 
+    def test_read_json_metadata(self):
+        unique_filename = get_unique_filename(extension="json")
+        try:
+            setup_json_lines_file(unique_filename, col_size=80)
+
+            # `lines=True` is for triggering Modin implementation,
+            # `orient="records"` should be set if `lines=True`
+            df = pd.read_json(unique_filename, lines=True, orient="records")
+            parts_width_cached = df._query_compiler._modin_frame._column_widths_cache
+            num_splits = len(df._query_compiler._modin_frame._partitions[0])
+            parts_width_actual = [
+                len(df._query_compiler._modin_frame._partitions[0][i].get().columns)
+                for i in range(num_splits)
+            ]
+
+            assert parts_width_cached == parts_width_actual
+
+        finally:
+            teardown_test_files([unique_filename])
+
 
 class TestExcel:
     @check_file_leaks