Saves the sequence to a json file. If root_array is True, then the sequence will be written to json with an array at the root. If it is False, then the sequence will be converted from a sequence of (Key, Value) pairs to a dictionary so that the json root is a dictionary.
(self, path, root_array=True, mode=WRITE_MODE, compression=None)
| 1540 | ) |
| 1541 | |
| 1542 | def to_json(self, path, root_array=True, mode=WRITE_MODE, compression=None): |
| 1543 | """ |
| 1544 | Saves the sequence to a json file. If root_array is True, then the sequence will be written |
| 1545 | to json with an array at the root. If it is False, then the sequence will be converted from |
| 1546 | a sequence of (Key, Value) pairs to a dictionary so that the json root is a dictionary. |
| 1547 | |
| 1548 | :param path: path to write file |
| 1549 | :param root_array: write json root as an array or dictionary |
| 1550 | :param mode: file open mode |
| 1551 | """ |
| 1552 | with universal_write_open(path, mode=mode, compression=compression) as output: |
| 1553 | if root_array: |
| 1554 | json.dump(self.to_list(), output) |
| 1555 | else: |
| 1556 | json.dump(self.to_dict(), output) |
| 1557 | |
| 1558 | def to_csv( |
| 1559 | self, |