A package that converts json to CSV, excel or other table formats
- JSON to excel converter
- Sample output
- Simple json
- Nested json
- json with array property
- Installation
- Usage
- Simple usage
- Streaming usage with restarts
- Arrays
- XLSX Formatting
- Cell format
- Column widths
- Row heights
- Urls
- Custom cell rendering
- Sample output
Sample output
Simple json
[ { "col1": "val1", "col2": "val2" } ]
the generated CSV/excel is:
col1 col2
==================
val1 val2
Nested json
[ { "col1": "val1", "col2": { "col21": "val21", "col22": "val22" } } ]
the generated CSV/excel is (in excel, col2 spans two cells horizontally):
col1 col2
col21 col22
=================================
val1 val21 val22
json with array property
[ { "col1": "val1", "col2": [ { "col21": "val21" }, { "col21": "val22" } ] } ]
the generated CSV/excel is (in excel, col2 spans two cells horizontally):
col1 col2
col21 col21
=================================
val1 val21 val22
Installation
pip install json-excel-converter[extra]
where extra is:
xlsxwriter
to use the xlsxwriter
Usage
Simple usage
from json_excel_converter import Converter from json_excel_converter.xlsx import Writer data = [ {'a': [1], 'b': 'hello'}, {'a': [1, 2, 3], 'b': 'world'} ] conv = Converter() conv.convert(data, Writer(file='/tmp/test.xlsx'))
Streaming usage with restarts
from json_excel_converter import Converter, LinearizationError from json_excel_converter.csv import Writer conv = Converter() writer = Writer(file='/tmp/test.csv') while True: try: data = get_streaming_data() # custom function to get iterator of data conv.convert_streaming(data, writer) break except LinearizationError: pass
Arrays
When the first row is processed, the library guesses the columns layout. In case of arrays,
a column (or more columns if the array contains json objects) is created for each
of the items in the array, as shown in the example above.
On subsequent rows the array might contain more items. The library reacts by adjusting
the number of columns in the layout and raising LinearizationError
as previous rows might
be already output.
Converter.convert_streaming
just raises this exception — it is the responsibility of caller
to take the right action.
Converter.convert
captures this error and restarts the processing. In case of CSV
this means truncating the output file to 0 bytes and processing the data again. XLSX writer
caches all the data before writing them to excel so the restart just means discarding the cache.
If you know the size of the array in advance, you should pass it in options. Then no
processing restarts are required and LinearizationError
is not raised.
from json_excel_converter import Converter, Options from json_excel_converter.xlsx import Writer data = [ {'a': [1]}, {'a': [1, 2, 3]} ] options = Options() options['a'].cardinality = 3 conv = Converter(options=options) writer = Writer(file='/tmp/test.xlsx') conv.convert(data, writer) # or conv.convert_streaming(data, writer) # no exception occurs here
XLSX Formatting
Cell format
XLSX writer enables you to format the header and data by passing an array of header_formatters or
data_formatters. Take these from json_excel_converter.xlsx.formats
package or create your own.
from json_excel_converter import Converter from json_excel_converter.xlsx import Writer from json_excel_converter.xlsx.formats import LastUnderlined, Bold, Centered, Format data = [ {'a': 'Hello'}, {'a': 'World'} ] w = Writer('/tmp/test3.xlsx', header_formats=( Centered, Bold, LastUnderlined, Format({ 'font_color': 'red' })), data_formats=( Format({ 'font_color': 'green' }),) ) conv = Converter() conv.convert(data, w)
See https://xlsxwriter.readthedocs.io/format.html for details on formats in xlsxwriter
Column widths
Pass the required column widths to writer:
w = Writer('/tmp/test3.xlsx', column_widths={ 'a': 20 })
Width of nested data can be specified as well:
data = [ {'a': {'b': 1, 'c': 2}} ] w = Writer('/tmp/test3.xlsx', column_widths={ 'a.b': 20, 'a.c': 30, })
To set the default column width, pass it as DEFAULT_COLUMN_WIDTH
property:
w = Writer('/tmp/test3.xlsx', column_widths={ DEFAULT_COLUMN_WIDTH: 20 })
Row heights
Row heights can be specified via the row_heights
writer option:
w = Writer('/tmp/test3.xlsx', row_heights={ DEFAULT_ROW_HEIGHT: 20, # a bit taller rows 1: 40 # extra tall header })
Urls
To render url, pass a function that gets data of a row and returns url to options
data = [ {'a': 'https://google.com'}, ] options = Options() options['a'].url = lambda data: data['a'] conv = Converter(options) conv.convert(data, w)
Note: this will only be rendered in XLSX output, CSV output will silently
ignore the link.
Custom cell rendering
Override the write_cell
method. The method receives cell_data
(instance of json_excel_converter.Value
) and data
(the original
data being written to this row). Note that this method is used both
for writing header and rows — for header the data
parameter is None.
class UrlWriter(Writer): def write_cell(self, row, col, cell_data, cell_format, data): if cell_data.path == 'a' and data: self.sheet.write_url(row, col, 'https://test.org/' + data['b'], string=cell_data.value) else: super().write_cell(row, col, cell_data, cell_format, data)
Добавить это приложение в закладки
Нажмите Ctrl + D, чтобы добавить эту страницу в избранное, или Esc, чтобы отменить действие.
Отправьте ссылку для скачивания на
Отправьте нам свой отзыв
Ой! Произошла ошибка.
Недопустимый файл. Убедитесь, что загружается правильный файл.
Ошибка успешно зарегистрирована.
Вы успешно сообщили об ошибке. Вы получите уведомление по электронной почте, когда ошибка будет исправлена.
Нажмите эту ссылку, чтобы посетить форумы.
Немедленно удалите загруженные и обработанные файлы.
Вы уверены, что хотите удалить файлы?
Введите адрес
Microsoft Excel Converter
The Microsoft Excel converter for JSON-Base64 makes it easy to get JSON-Base64 data into and out of Microsoft Excel in a format suitable for most programming languages. Microsoft Excel is not required to install or run this application.
Supported file formats are: .jb64, .xls, and .xlsx
This application is public domain (view license).
System Requirements
The system requirements to run the Microsoft Excel converter application are as follows:
- Windows XP or later.
- .NET Framework 3.5 SP1 or later.
It is highly likely that the necessary components to run this application are already installed.
Note to Mono users: The AeroWizard component apparently causes some usability issues under Mono.
Installation
Installation is easy. First:
Download the Microsoft Excel converter application
Then extract the contents into its own directory. The application runs standalone without needing to be installed via an installer. Files with the ‘.jb64’ file extension may be associated with the main executable to expedite transformations.
Converting Files
The application aims to make converting between Excel and JSON-Base64 as easy and quick as possible. The conversion process is broken down into four logical steps:
- Select source and destination files. Note that drag-and-drop is supported.
- Configure field mapping.
- Perform the conversion.
- Display results and optionally start Microsoft Excel if the destination file is a recognized Excel file format.
The application is a wizard-style application that proceeds through these logical steps in a seamless fashion. A screenshot is available above that shows the field mapping page of the wizard.
If the ‘.jb64’ file extension is associated with the executable, the entire process is very streamlined when going from a web server that outputs JSON-Base64 and importing it into Excel. Using JSON-Base64 reduces the need for bringing heavy libraries into play on a web server that output .xls(x) files.
Building From Source
If you are a software developer familiar with Visual Studio, below is the link to download the public domain source code to this application:
Download the Microsoft Excel converter source code
Everything needed to build the application is in the ZIP file. The application is written in C# and depends on the included libraries:
- C# JSON-Base64 — For JSON-Base64 support.
- JSON.NET — For JSON support, via NuGet.
- NPOI v2.x — For reading and writing Excel files without needing Excel.
- AeroWizard — For the wizard-style dialog.
In theory, it should be possible to simply open the Solution (.sln) file and build and run it. In practice, it might be a bit more difficult as Visual Studio might not find the various libraries in their expected locations, requiring some effort to get a working build.
The application source code for the wizard is organized loosely into the order of the conversion process. The most interesting aspect is the generic source and destination classes. In theory these could be expanded to support conversions between any common file formats, but there is little point in doing that. It is an application that does what it does and does it well enough.
Note that strings are hardcoded in English. Translating to other written languages will require making the application into a multilingual app first.
If you make some really nice changes, consider submitting them back to the project but note that source code in the wizard should be under the public domain and third-party libraries under a very liberal license (e.g. MIT) to be considered for inclusion.
JSON to excel converter
A package that converts json to CSV, excel or other table formats
- JSON to excel converter
- Sample output
- Simple json
- Nested json
- json with array property
- Installation
- Usage
- Simple usage
- Streaming usage with restarts
- Arrays
- XLSX Formatting
- Cell format
- Column widths
- Row heights
- Urls
- Custom cell rendering
- Sample output
Sample output
Simple json
[ { "col1": "val1", "col2": "val2" } ]
the generated CSV/excel is:
col1 col2
==================
val1 val2
Nested json
[ { "col1": "val1", "col2": { "col21": "val21", "col22": "val22" } } ]
the generated CSV/excel is (in excel, col2 spans two cells horizontally):
col1 col2
col21 col22
=================================
val1 val21 val22
json with array property
[ { "col1": "val1", "col2": [ { "col21": "val21" }, { "col21": "val22" } ] } ]
the generated CSV/excel is (in excel, col2 spans two cells horizontally):
col1 col2
col21 col21
=================================
val1 val21 val22
Installation
pip install json-excel-converter[extra]
where extra is:
xlsxwriter
to use the xlsxwriter
Usage
Simple usage
from json_excel_converter import Converter from json_excel_converter.xlsx import Writer data = [ {'a': [1], 'b': 'hello'}, {'a': [1, 2, 3], 'b': 'world'} ] conv = Converter() conv.convert(data, Writer(file='/tmp/test.xlsx'))
Streaming usage with restarts
from json_excel_converter import Converter, LinearizationError from json_excel_converter.csv import Writer conv = Converter() writer = Writer(file='/tmp/test.csv') while True: try: data = get_streaming_data() # custom function to get iterator of data conv.convert_streaming(data, writer) break except LinearizationError: pass
Arrays
When the first row is processed, the library guesses the columns layout. In case of arrays,
a column (or more columns if the array contains json objects) is created for each
of the items in the array, as shown in the example above.
On subsequent rows the array might contain more items. The library reacts by adjusting
the number of columns in the layout and raising LinearizationError
as previous rows might
be already output.
Converter.convert_streaming
just raises this exception — it is the responsibility of caller
to take the right action.
Converter.convert
captures this error and restarts the processing. In case of CSV
this means truncating the output file to 0 bytes and processing the data again. XLSX writer
caches all the data before writing them to excel so the restart just means discarding the cache.
If you know the size of the array in advance, you should pass it in options. Then no
processing restarts are required and LinearizationError
is not raised.
from json_excel_converter import Converter, Options from json_excel_converter.xlsx import Writer data = [ {'a': [1]}, {'a': [1, 2, 3]} ] options = Options() options['a'].cardinality = 3 conv = Converter(options=options) writer = Writer(file='/tmp/test.xlsx') conv.convert(data, writer) # or conv.convert_streaming(data, writer) # no exception occurs here
XLSX Formatting
Cell format
XLSX writer enables you to format the header and data by passing an array of header_formatters or
data_formatters. Take these from json_excel_converter.xlsx.formats
package or create your own.
from json_excel_converter import Converter from json_excel_converter.xlsx import Writer from json_excel_converter.xlsx.formats import LastUnderlined, Bold, Centered, Format data = [ {'a': 'Hello'}, {'a': 'World'} ] w = Writer('/tmp/test3.xlsx', header_formats=( Centered, Bold, LastUnderlined, Format({ 'font_color': 'red' })), data_formats=( Format({ 'font_color': 'green' }),) ) conv = Converter() conv.convert(data, w)
See https://xlsxwriter.readthedocs.io/format.html for details on formats in xlsxwriter
Column widths
Pass the required column widths to writer:
w = Writer('/tmp/test3.xlsx', column_widths={ 'a': 20 })
Width of nested data can be specified as well:
data = [ {'a': {'b': 1, 'c': 2}} ] w = Writer('/tmp/test3.xlsx', column_widths={ 'a.b': 20, 'a.c': 30, })
To set the default column width, pass it as DEFAULT_COLUMN_WIDTH
property:
w = Writer('/tmp/test3.xlsx', column_widths={ DEFAULT_COLUMN_WIDTH: 20 })
Row heights
Row heights can be specified via the row_heights
writer option:
w = Writer('/tmp/test3.xlsx', row_heights={ DEFAULT_ROW_HEIGHT: 20, # a bit taller rows 1: 40 # extra tall header })
Urls
To render url, pass a function that gets data of a row and returns url to options
data = [ {'a': 'https://google.com'}, ] options = Options() options['a'].url = lambda data: data['a'] conv = Converter(options) conv.convert(data, w)
Note: this will only be rendered in XLSX output, CSV output will silently
ignore the link.
Custom cell rendering
Override the write_cell
method. The method receives cell_data
(instance of json_excel_converter.Value
) and data
(the original
data being written to this row). Note that this method is used both
for writing header and rows — for header the data
parameter is None.
class UrlWriter(Writer): def write_cell(self, row, col, cell_data, cell_format, data): if cell_data.path == 'a' and data: self.sheet.write_url(row, col, 'https://test.org/' + data['b'], string=cell_data.value) else: super().write_cell(row, col, cell_data, cell_format, data)
Java library that easily converts a Json array to Excel or CSV
Features
- Converts any Json array to Excel
- Converts any Json array to CSV
- Customized column names
License
GNU General Public License version 2.0 (GPLv2), Apache License V2.0
eSkill features an extensive modular subject library that enables users to create single or multi-subject based exams for applicants. eSkill allows users to edit existing questions, upload or generate their own test content with the application’s editor. eSkill also provides users with a number of job-based assessments that test employee skills for different positions in different industries.
User Ratings
1.0
out of 5 stars
★★★★★
★★★★
★★★
★★
★
ease
1 of 5
2 of 5
3 of 5
4 of 5
5 of 5
1 / 5
features
1 of 5
2 of 5
3 of 5
4 of 5
5 of 5
3 / 5
design
1 of 5
2 of 5
3 of 5
4 of 5
5 of 5
3 / 5
support
1 of 5
2 of 5
3 of 5
4 of 5
5 of 5
3 / 5
User Reviews
- All
- ★★★★★
- ★★★★
- ★★★
- ★★
- ★
-
Alas, java -jar json2excel.jar will give you «no main manifest attribute, in json2excel.jar»
Similarly java -jar json2excel.jar com.converter.json.csv.Json2Csv gives the same, and
java -cp ./json2excel.jar com.converter.json.csv.Json2Csv throws an exception for a lacking net/sf/json/JSONArray
bother!
Read more reviews >
Additional Project Details
Programming Language
Java