json-2-csv


License

License

MIT
Categories

Categories

CSV Data Data Formats JSON
GroupId

GroupId

com.github.agourlay
ArtifactId

ArtifactId

json-2-csv_2.11
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

json-2-csv
json-2-csv
Project URL

Project URL

https://github.com/agourlay/json-2-csv
Project Organization

Project Organization

com.github.agourlay
Source Code Management

Source Code Management

https://github.com/agourlay/json-2-csv.git

Download json-2-csv_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.agourlay/json-2-csv_2.11/ -->
<dependency>
    <groupId>com.github.agourlay</groupId>
    <artifactId>json-2-csv_2.11</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.agourlay/json-2-csv_2.11/
implementation 'com.github.agourlay:json-2-csv_2.11:0.3.0'
// https://jarcasting.com/artifacts/com.github.agourlay/json-2-csv_2.11/
implementation ("com.github.agourlay:json-2-csv_2.11:0.3.0")
'com.github.agourlay:json-2-csv_2.11:jar:0.3.0'
<dependency org="com.github.agourlay" name="json-2-csv_2.11" rev="0.3.0">
  <artifact name="json-2-csv_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.agourlay', module='json-2-csv_2.11', version='0.3.0')
)
libraryDependencies += "com.github.agourlay" % "json-2-csv_2.11" % "0.3.0"
[com.github.agourlay/json-2-csv_2.11 "0.3.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.11
org.spire-math : jawn-ast_2.11 jar 0.11.0
com.github.tototoshi : scala-csv_2.11 jar 1.3.4

test (2)

Group / Artifact Type Version
commons-io : commons-io jar 2.5
org.scalatest : scalatest_2.11 jar 3.0.3

Project Modules

There are no modules declared in this project.

json-2-csv Build Status Maven Central Join the chat at https://gitter.im/agourlay/json-2-csv

A library transforming JSON collections into CSV files.

Features

  • ingests JSON collections from a File or from a LazyList[String].
  • turns nested JSON objects into extra CSV columns and lines.
  • works in a streaming fashion with a small memory footprint.

Limitations

  • the JSON objects in the collection level must share a common structure.
  • the first element should be a complete definition of the structure, the following elements can be sparse.
  • the transformation stops at the first error encountered.

Input & output formats

A file containing a JSON collection like this is transformed into a CSV file like that.

When nested objects are turned into extra columns the content of the parent object is not repeated.

APIs

Two methods on the Json2Csv object returning an Either of the number of CSV lines written to the OutputStream:

def convert(file: File, resultOutputStream: OutputStream): Either[Exception, Long]

def convert(chunks:  LazyList[String], resultOutputStream: OutputStream): Either[Exception, Long]

Usage example

object Boot {
  def main(args: Array[String]): Unit = {
    if (args.isEmpty) println("Error - Provide the CSV file path as argument ")
    else {
      val output = new FileOutputStream("result-json.csv")
      Json2Csv.convert(new File(args(0)), output) match {
        case Right(nb) => println(s"$nb CSV lines written to 'result-json.csv'")
        case Left(e)  => println(s"Something bad happened $e")
      }
    }
  }
}

Installation

libraryDependencies ++= Seq(
  "com.github.agourlay" %% "json-2-csv" % "0.5.4",
  ...
)

License

This code is open source software licensed under the MIT License.

Versions

Version
0.3.0
0.2.3