Code Monkey home page Code Monkey logo

json-to-csv's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

json-to-csv's Issues

Append To CSV

hi,, i get java heap memory when i create array list to make "List<Map<String, String>> flatJson = JSONFlattener.parseJson(listDoc.toString());" because i have hundreds row of data.
so how i can append it one by one using "CSVWriter.writeToFile(CSVWriter.getCSV(flatJson, ";"), "");" on exist file???

Importancia y Uso del Patrón Adapter en el Código Base

Actualmente, estamos analizando el diseño y la arquitectura del código base para identificar oportunidades de mejora y optimización. Después de un análisis exhaustivo, hemos notado una situación en la que la implementación del patrón de diseño Adapter podría proporcionar beneficios significativos para el sistema.

Propuesta:
La implementación del patrón Adapter permitirá adaptar las interfaces de las bibliotecas y componentes externos a una interfaz común, lo que simplificará su uso y aumentará la flexibilidad de nuestro sistema. Al utilizar el Adapter, podemos:

Mejorar la Interoperabilidad: El Adapter nos permitirá trabajar con componentes externos incompatibles a través de una interfaz común. Esto mejorará la colaboración entre diferentes partes del sistema y aumentará la coherencia en el código.

Facilitar la Mantenibilidad: Al encapsular la adaptación en las clases Adapter, podremos gestionar los cambios y actualizaciones en las bibliotecas externas con mayor facilidad. No tendremos que realizar modificaciones extensas en todo el sistema cada vez que haya cambios en las interfaces de las bibliotecas.

Promover la Reutilización: Al implementar el Adapter, crearemos una capa de adaptación independiente que puede reutilizarse en diferentes partes del sistema. Esto evitará la duplicación de código y mejorará la coherencia en toda la base de código.

Acción Propuesta:
Recomendamos llevar a cabo una revisión detallada de las áreas en las que interactuamos con componentes externos incompatibles. Esta refactorización ayudará a simplificar el código, reducir la complejidad y mejorar la mantenibilidad en el futuro.

Impacto Esperado:
La implementación del patrón Adapter traerá claros beneficios en términos de coherencia, mantenibilidad y reutilización de código. Además, facilitará la integración de nuevas bibliotecas y componentes en el futuro, lo que acelerará el desarrollo y permitirá una evolución más ágil del sistema.

simple.json is not found

[INFO] [2016-11-09 08:41:22] JSONFlattener:130 - Handle the JSON String as JSON Array
[ERROR] [2016-11-09 08:41:22] JSONFlattener:107 - JsonFlattener#ParseJson(file, encoding) IOException:
java.io.FileNotFoundException: File 'files\simple.json' does not exist
at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:299)
at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:1711)
at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:1734)
at org.jsontocsv.parser.JSONFlattener.parseJson(JSONFlattener.java:104)
at org.jsontocsv.Main.main(Main.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Exception in thread "main" java.lang.NullPointerException
at org.jsontocsv.writer.CSVWriter.collectHeaders(CSVWriter.java:110)
at org.jsontocsv.writer.CSVWriter.getCSV(CSVWriter.java:58)
at org.jsontocsv.Main.main(Main.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Design Patterns

For educational reasons in this repository identify 2 design patterns that can be applied.

Chain of Responsibility
The JSON to CSV conversion job can be modeled through a chain of responsibilities, where each type of conversion will evaluate whether or not it can convert the file.

public class Main {
public static void main(String[] args) throws Exception {
/*
* Parse a JSON String and convert it to CSV
*/
List<Map<String, String>> flatJson = JSONFlattener.parseJson(jsonString());
// Using the default separator ','
CSVWriter.writeToFile(CSVWriter.getCSV(flatJson), "files/sample_string.csv");
/*
* Parse a JSON File and convert it to CSV
*/
flatJson = JSONFlattener.parseJson(new File("files/simple.json"), "UTF-8");
// Using ';' as separator
CSVWriter.writeToFile(CSVWriter.getCSV(flatJson, ";"), "files/sample_file.csv");
/*
* Parse JSON from URL and convert it to CSV
*/
flatJson = JSONFlattener.parseJson(new URI("http://echo.jsontest.com/firstname/Brahim/lastName/Arkni"));
// Using '\t' as separator
CSVWriter.writeToFile(CSVWriter.getCSV(flatJson, "\t"), "files/sample_uri.csv");
/*
* Parse a Large JSON File and convert it to CSV
*/
flatJson = JSONFlattener.parseJson(new File("files/sample_large.json"), "UTF-8");
// Using ';' as separator
Set<String> header = CSVWriter.collectOrderedHeaders(flatJson);
// the intention is generate a csv file with specific headers - not all
CSVWriter.writeLargeFile(flatJson, ";", "files/sample_largeFile.csv", header);
}
private static String jsonString() {
return "[" +
" {" +
" \"studentName\": \"Foo\"," +
" \"Age\": \"12\"," +
" \"subjects\": [" +
" {" +
" \"name\": \"English\"," +
" \"marks\": \"40\"" +
" }," +
" {" +
" \"name\": \"History\"," +
" \"marks\": \"50\"" +
" }" +
" ]" +
" }" +
"]";
}
}

Remaining as follows

image
image
image
image
image
image

UML class diagram
image

Facade
Following the previous pattern as a subsystem, the facade pattern can be used to give easy access to the entire chain of handlers.
image

Remaining as follows

image

UML class diagram

image

JAVA.NIO. Package not found

How to pull the JAVA.NIO Package in this projects, i tried a lot but did not get solution could you explain me please. Thanks in advance.

Chain of responsibility

El código de las diferentes formas para convertir los archivos se encuentra originalmente en
la clase Main. se debe crear una clase abstracta que tenga sus clases concretas para que funcionen como manejadores, por si se quiere transformar un archivo JSON, pasará por cada manejador y verificará si es capaz
de convertirlo a formato CSV, caso contrario pasará al siguiente, hasta lograr convertir el
documento.
figura

Code Smelles

Hello, for academic reasons my group and I found a code smell that is ["comments"
aviso1

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.