Package smile.io

Class JSON

java.lang.Object
smile.io.JSON

public class JSON extends Object
Reads JSON datasets. No nested objects are currently allowed.
  • Constructor Details

    • JSON

      public JSON()
      Constructor.
  • Method Details

    • schema

      public JSON schema(StructType schema)
      Sets the schema.
      Parameters:
      schema - the data schema.
      Returns:
      this object.
    • charset

      public JSON charset(Charset charset)
      Sets the charset.
      Parameters:
      charset - the charset of file.
      Returns:
      this object.
    • mode

      public JSON mode(JSON.Mode mode)
      Sets the file mode (single-line or multi-line).
      Parameters:
      mode - the file mode.
      Returns:
      this object.
    • read

      public DataFrame read(Path path) throws IOException
      Reads a JSON file.
      Parameters:
      path - the input file path.
      Returns:
      the data frame.
      Throws:
      IOException - when fails to read the file.
    • read

      public DataFrame read(Path path, int limit) throws IOException
      Reads a JSON file.
      Parameters:
      path - the input file path.
      limit - the number number of records to read.
      Returns:
      the data frame.
      Throws:
      IOException - when fails to read the file.
    • read

      public DataFrame read(String path) throws IOException, URISyntaxException
      Reads a JSON file.
      Parameters:
      path - the input file path.
      Returns:
      the data frame.
      Throws:
      IOException - when fails to read the file.
      URISyntaxException - when the file path syntax is wrong.
    • read

      public DataFrame read(String path, int limit) throws IOException, URISyntaxException
      Reads a JSON file.
      Parameters:
      path - the input file path.
      limit - the number number of records to read.
      Returns:
      the data frame.
      Throws:
      IOException - when fails to read the file.
      URISyntaxException - when the file path syntax is wrong.
    • read

      public DataFrame read(BufferedReader reader, int limit) throws IOException
      Reads a limited number of records from a JSON file.
      Parameters:
      reader - the file reader.
      limit - the number number of records to read.
      Returns:
      the data frame.
      Throws:
      IOException - when fails to read the file.
    • inferSchema

      public StructType inferSchema(BufferedReader reader, int limit) throws IOException
      Infer the schema from the top n rows.
      1. Infer type of each row.
      2. Merge row types to find common type
      3. String type by default.
      Parameters:
      reader - the file reader.
      limit - the number number of records to read.
      Returns:
      the data frame.
      Throws:
      IOException - when fails to read the file.