Repository: pandas-dev/pandas

Issue:
Error when read_json created by to_json with orient='table and index=False
#### Code Sample, a copy-pastable example if possible

```python
import pandas as pd
df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
dfjson = df.to_json(orient='table', index=False)
result = pd.read_json(dfjson, orient='table')
```
#### Problem description
An error is raised while the original DataFrame should be recovered:
```shell
pandas/io/json/table_schema.py in parse_table_schema(json, precise_float)
    315     df = df.astype(dtypes)
    316 
--> 317     df = df.set_index(table['schema']['primaryKey'])
    318     if len(df.index.names) == 1:
    319         if df.index.name == 'index':

KeyError: 'primaryKey'
```

My pandas version is 0.24.0.

#### Expected Output
The expected output `result` should be the original DataFrame `df`.

#### Output of ``pd.show_versions()``

<details>
pandas/util/_print_versions.py in <lambda>(mod)
     78         ("blosc", lambda mod: mod.__version__),
     79         ("bottleneck", lambda mod: mod.__version__),
---> 80         ("tables", lambda mod: mod.__version__),
     81         ("numexpr", lambda mod: mod.__version__),
     82         ("feather", lambda mod: mod.__version__),

AttributeError: module 'tables' has no attribute '__version__'
</details>



Discussion:
Thanks for the report. Investigation and PRs are always welcome.

Resolving patch:
diff --git a/pandas/io/json/table_schema.py b/pandas/io/json/table_schema.py
--- a/pandas/io/json/table_schema.py
+++ b/pandas/io/json/table_schema.py
@@ -314,12 +314,13 @@ def parse_table_schema(json, precise_float):
 
     df = df.astype(dtypes)
 
-    df = df.set_index(table['schema']['primaryKey'])
-    if len(df.index.names) == 1:
-        if df.index.name == 'index':
-            df.index.name = None
-    else:
-        df.index.names = [None if x.startswith('level_') else x for x in
-                          df.index.names]
+    if 'primaryKey' in table['schema']:
+        df = df.set_index(table['schema']['primaryKey'])
+        if len(df.index.names) == 1:
+            if df.index.name == 'index':
+                df.index.name = None
+        else:
+            df.index.names = [None if x.startswith('level_') else x for x in
+                              df.index.names]
 
     return df


Test patch:
diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py
--- a/pandas/tests/io/json/test_pandas.py
+++ b/pandas/tests/io/json/test_pandas.py
@@ -1262,3 +1262,13 @@ def test_index_false_error_to_json(self, orient):
                "'orient' is 'split' or 'table'")
         with pytest.raises(ValueError, match=msg):
             df.to_json(orient=orient, index=False)
+
+    @pytest.mark.parametrize('orient', ['split', 'table'])
+    @pytest.mark.parametrize('index', [True, False])
+    def test_index_false_from_json_to_json(self, orient, index):
+        # GH25170
+        # Test index=False in from_json to_json
+        expected = DataFrame({'a': [1, 2], 'b': [3, 4]})
+        dfjson = expected.to_json(orient=orient, index=index)
+        result = read_json(dfjson, orient=orient)
+        assert_frame_equal(result, expected)