Skip to main content

This is the `json-ops` package, intended to provide a collection of utilities for working with JSON data.

Project description

json-ops

This is the json-ops package, intended to provide a collection of utilities for working with JSON data. Currently, it includes functionality to convert CSV and Excel files and strings to JSON format. More features will be added in the future.

Modules

csv_to_json.py

This script provides functionality to convert CSV (Comma Separated Values) files and strings to JSON (JavaScript Object Notation) format.

Features

  • Converts CSV files to JSON files.
  • Converts CSV strings to JSON strings.
  • Handles basic data type conversions (integer, float, boolean).

Usage

Converting a CSV file to JSON
from json_converter.csv_to_json import convert_csv_file

input_file = 'path/to/your/input.csv'
output_file = 'path/to/your/output.json'

success = convert_csv_file(input_file, output_file)

if success:
    print(f"Successfully converted {input_file} to {output_file}")
else:
    print(f"Failed to convert {input_file}")
Converting a CSV string to JSON
from json_converter.csv_to_json import convert_csv_string

csv_string = "Name,Age,City\\nAlice,30,New York\\nBob,25,London"
json_string = convert_csv_string(csv_string)

if json_string:
    print(json_string)
else:
    print("Failed to convert CSV string")

Limitations

  • No support for nested input files: This converter is designed to work with flat CSV files. It does not support CSV files with nested structures or hierarchical data.

excel_to_json.py

This script provides functionality to convert Excel files and strings to nested JSON format based on column names.

Features

  • Converts Excel files to nested JSON files.
  • Converts Excel file content (bytes) to nested JSON strings.
  • Uses column names with dot notation (e.g., address.city) to create nested JSON structures.

Usage

Converting an Excel file to nested JSON
from json_converter.excel_to_json import convert_excel_file

input_file = 'path/to/your/input.xlsx'
output_file = 'path/to/your/output.json'

success = convert_excel_file(input_file, output_file)

if success:
    print(f"Successfully converted {input_file} to {output_file}")
else:
    print(f"Failed to convert {input_file}")
Converting Excel file content (bytes) to nested JSON
from json_converter.excel_to_json import convert_excel_string
import pandas as pd
import io

data = {'address.city': ['New York', 'London'], 'name': ['Alice', 'Bob']}
df = pd.DataFrame(data)
buffer = io.BytesIO()
df.to_excel(buffer, index=False)
excel_content_bytes = buffer.getvalue()

json_string = convert_excel_string(excel_content_bytes)

if json_string:
    print(json_string)
else:
    print("Failed to convert Excel content")

Limitations

  • Requires column names to follow a dot notation convention for creating nested structures.
  • Handles basic data types as inferred by pandas.

Installation

No specific installation is required. Ensure you have Python and the pandas library installed. If you intend to run the tests, you will also need pytest and openpyxl:

pip install pandas openpyxl pytest

Running Tests

To run the tests for the modules:

pytest tests/test_csv_to_json.py
pytest tests/test_excel_to_json.py

License

This software is for individual, non-commercial use only. Commercial use requires explicit permission from the author. Please contact vineettiwari863@gmail.com for inquiries regarding commercial licensing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_ops-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_ops-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file json_ops-0.1.0.tar.gz.

File metadata

  • Download URL: json_ops-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.1

File hashes

Hashes for json_ops-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bcce3be8e07ad91938aa10312a031deea496fc9e0c2cc505789241a4c0e6f273
MD5 4b8e77f23de4376d4b3271baa083b03d
BLAKE2b-256 9453bafc44e969c9e01074e7699865c53fc5e3a29559c96314b34ebe1e95bc5c

See more details on using hashes here.

File details

Details for the file json_ops-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: json_ops-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.1

File hashes

Hashes for json_ops-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55ef9aabb7ee443e79f12a61388a9fa9561adeb1e07f68d7376f04924835c885
MD5 cf8b1249f6b7d13e913dfb5decfc9dbb
BLAKE2b-256 a17d5da56cc55d063894344af229b55f16bcd70447b872c618009190f4a4f877

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page