You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

com.github.opendevl:json2flat

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.opendevl:json2flat

Converting JSON documents to flat CSV


Version published
Maintainers
2

Readme

Source

Json2Flat

This library converts JSON documents to CSV.
It uses google-gson and JsonPath for conversion.
Click here for a quick evaluation.

Maven Central

Dependency for Maven.

<dependency>
    <groupId>com.github.opendevl</groupId>
    <artifactId>json2flat</artifactId>
    <version>1.0.3</version>
</dependency>

Example

String str = new String(Files.readAllBytes(Paths.get("/path/to/source/file.json")));

JFlat flatMe = new JFlat(str);

//get the 2D representation of JSON document
List<Object[]> json2csv = flatMe.json2Sheet().getJsonAsSheet();

//write the 2D representation in csv format
flatMe.write2csv("/path/to/destination/file.json");

OR

String str = new String(Files.readAllBytes(Paths.get("/path/to/source/file.json")));

JFlat flatMe = new JFlat(str);

//directly write the JSON document to CSV
flatMe.json2Sheet().write2csv("/path/to/destination/file.json");

//directly write the JSON document to CSV but with delimiter
flatMe.json2Sheet().write2csv("/path/to/destination/file.json", '|');

Input JSON

{
    "store": {
	    
	    
		"book": [
		    {
		        "name":"dasd",
		        "category": "reference",
		        "author": "Nigel Rees",
		        "title": "Sayings of the Century",
		        "price": 8.95,
		        "marks" : [3,99,89]
		    },
		    {
		        "category": "fiction",
		        "author": "Evelyn Waugh",
		        "title": "Sword of Honour",
		        "price": 12.99,
		        "marks" : [3,99,89,34,67567]
		    },
		    {
		        "category": "fiction",
		        "author": "Herman Melville",
		        "title": "Moby Dick",
		        "isbn": "0-553-21311-3",
		        "price": 8.99,
		        "marks" : [3,99,89]
		    },
		    {
		        "category": "fiction",
		        "author": "J. R. R. Tolkien",
		        "title": "The Lord of the Rings",
		        "isbn": "0-395-19395-8",
		        "price": 22.99,
		        "marks" : []
		    }
		]
	}
}

Output CSV

/store/book/name/store/book/category/store/book/author/store/book/title/store/book/price/store/book/marks/0/store/book/marks/1/store/book/marks/2/store/book/marks/3/store/book/marks/4/store/book/isbn
dasdreferenceNigel ReesSayings of the Century8.9539989
fictionEvelyn WaughSword of Honour12.99399893467567
fictionHerman MelvilleMoby Dick8.99399890-553-21311-3
fictionJ. R. R. TolkienThe Lord of the Rings22.990-395-19395-8

If you want to remove the "/" from header name then use the headerSeparator() function e.g.

To change /store/book/name to store book name

flatMe.json2Sheet().headerSeparator().write2csv("/path/to/destination/file.json");

To change /store/book/name to store_book_name

flatMe.json2Sheet().headerSeparator("_").write2csv("/path/to/destination/file.json");

Click here for JavaDoc.

FAQs

Package last updated on 22 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc