Giter VIP home page Giter VIP logo

bajson's Introduction

bajson

library for converting to/from json

pypi Supported Python Versions

Install

 $ pip install bajson

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 convert 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 (it can be added in future release)

[
  {
    "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

bajson's People

Contributors

bakyazi avatar

Watchers

James Cloos avatar  avatar

Forkers

retryme

bajson's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.