Class JFlat


  • public class JFlat
    extends java.lang.Object
    This class converts a Json document in a 2D matrix format like CSV.
    Version:
    1.0.3
    Author:
    opendevl
    • Constructor Summary

      Constructors 
      Constructor Description
      JFlat​(java.lang.String jsonString)
      This constructor takes a Json as string.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<java.lang.Object[]> getJsonAsSheet()
      This method returns the sheet matrix.
      java.util.List<java.lang.String> getUniqueFields()
      This method returns unique fields of the json
      JFlat headerSeparator()
      This method replaces the default header separator i.e.
      JFlat headerSeparator​(java.lang.String separator)
      This method replaces the default header separator i.e.
      JFlat json2Sheet()
      This method does some pre processing and then calls make2D() to get the 2D representation of Json document.
      java.lang.String write2csv​(char delimiter)
      This method returns the 2D representation in csv format as string with custom delimiter set by user.
      void write2csv​(java.lang.String destination)
      This method writes the 2D representation in csv format with ',' as default delimiter.
      void write2csv​(java.lang.String destination, char delimiter)
      This method writes the 2D representation in csv format with custom delimiter set by user.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JFlat

        public JFlat​(java.lang.String jsonString)
        This constructor takes a Json as string.
        Parameters:
        jsonString - it takes Json as string.
    • Method Detail

      • json2Sheet

        public JFlat json2Sheet()
        This method does some pre processing and then calls make2D() to get the 2D representation of Json document.
        Returns:
        returns a JFlat object
      • headerSeparator

        public JFlat headerSeparator()
                              throws java.lang.Exception
        This method replaces the default header separator i.e. "/" with a space.
        Returns:
        JFlat
        Throws:
        java.lang.Exception
      • headerSeparator

        public JFlat headerSeparator​(java.lang.String separator)
                              throws java.lang.Exception
        This method replaces the default header separator i.e. "/" with a custom separator provided by user.
        Parameters:
        separator -
        Returns:
        JFlat
        Throws:
        java.lang.Exception
      • getJsonAsSheet

        public java.util.List<java.lang.Object[]> getJsonAsSheet()
        This method returns the sheet matrix.
        Returns:
        List
        • getUniqueFields

          public java.util.List<java.lang.String> getUniqueFields()
          This method returns unique fields of the json
          Returns:
          List
        • write2csv

          public void write2csv​(java.lang.String destination)
                         throws java.io.FileNotFoundException,
                                java.io.UnsupportedEncodingException
          This method writes the 2D representation in csv format with ',' as default delimiter.
          Parameters:
          destination - it takes the destination path for the csv file.
          Throws:
          java.io.FileNotFoundException
          java.io.UnsupportedEncodingException
        • write2csv

          public void write2csv​(java.lang.String destination,
                                char delimiter)
                         throws java.io.FileNotFoundException,
                                java.io.UnsupportedEncodingException
          This method writes the 2D representation in csv format with custom delimiter set by user.
          Parameters:
          destination - it takes the destination path for the csv file.
          delimiter - it represents the delimiter set by user.
          Throws:
          java.io.FileNotFoundException
          java.io.UnsupportedEncodingException
        • write2csv

          public java.lang.String write2csv​(char delimiter)
          This method returns the 2D representation in csv format as string with custom delimiter set by user.
          Parameters:
          delimiter - it represents the delimiter set by user.