json-2-csv


License

License

MIT
Categories

Categories

CSV Data Data Formats JSON
GroupId

GroupId

com.github.agourlay
ArtifactId

ArtifactId

json-2-csv_2.12
Last Version

Last Version

0.4.2
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.12

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
org.typelevel : jawn-ast_2.12 jar 0.14.1
com.github.tototoshi : scala-csv_2.12 jar 1.3.5

test (2)

Group / Artifact Type Version
commons-io : commons-io jar 2.6
org.scalatest : scalatest_2.12 jar 3.0.5

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.3",
  ...
)

License

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

Versions

Version
0.4.2
0.4.1
0.4.0
0.3.0
0.2.3
0.2.2