Skip to main content

library for converting to/from json

Project description

bajson

library for converting to/from json

pypi Supported Python Versions

Usage

JSON to CSV

  • the root of the input json should be in list format

    Invalid

    "data": [
        {
          "data": "value",
          "data1": "value1"
        },
        {
          "data": "value2",
          "data1": "value3"
        },
      ]
    

    Valid

    [
      {
        "data": "value",
        "data1": "value1"
      },
      {
        "data": "value2",
        "data1": "value3"
      },
    ]
    
  • Converting nested json objects

    [
      {
        "data": {
              "firstkey": "firstvalue",
              "secondvalue": "secondvalue",
            },           
        "data1": "value1"
      },
      {
        "data": {
              "firstkey": "firstvalue1",
              "secondvalue": "secondvalue1",
            },           
        "data1": "value2"
      },
    ]
    
    data.firstkey data.secondkey data1
    firstvalue secondvalue value1
    firstvalue1 secondvalue1 value2
  • Converting arrays in json objects

    [
      {
        "data": [
              "firstvalue",
              "secondvalue",
            ],           
        "data1": "value1"
      },
      {
        "data": [
              "firstvalue1",
            ],           
        "data1": "value2"
      },
    ]
    
    data.0 data.1 data1
    firstvalue secondvalue value1
    firstvalue1 value2

Code Example

from bajson.libcsv import json_to_csv

json_to_csv("input.json", "output.csv")

CSV to JSON

bajson can conver csv file to json format vice versa. Formats above are valid for this operation too. However there is one exception about array conversion,

If csv headers are as follows

data.0 data.1 data1
firstvalue secondvalue value1
firstvalue1 value2

This will be converted to object form instead of array form

[
  {
    "data": {
          "0": "firstvalue",
          "1": "secondvalue",
        },           
    "data1": "value1"
  },
  {
    "data": {
          "0": "firstvalue1",
        },           
    "data1": "value2"
  },
]

Code Example

from bajson.libcsv import csv_to_json

csv_to_json("input.csv", "output.json")

Future features

  • Support string input/output parameters
  • JSON <==> XML

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

bajson-0.0.6.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file bajson-0.0.6.tar.gz.

File metadata

  • Download URL: bajson-0.0.6.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.5

File hashes

Hashes for bajson-0.0.6.tar.gz
Algorithm Hash digest
SHA256 65771f3cbe9db2b089a83ef751bb7e89e1a862b5576d53747bc59f702f600f26
MD5 55e797cc521c207fdb062eef392f5db1
BLAKE2b-256 b7de24ad932f53f4de9ab8216bb44a54abd2a5c72680897e2d09d75c29f93ad1

See more details on using hashes here.

Supported by

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