Class JSONUtils

java.lang.Object
io.github.the_sdet.json.JSONUtils

public class JSONUtils extends Object
This class handles all JSON related Utilities and Helper methods
Author:
Pabitra Swain ([email protected])
  • Constructor Details

    • JSONUtils

      public JSONUtils()
  • Method Details

    • readJsonFromFile

      public static String readJsonFromFile(String filePath) throws IOException
      This method reads a JSON file and returns the content as String
      Parameters:
      filePath - JSON file path
      Returns:
      String content of the file
      Throws:
      IOException - throws IOException
    • writeJsonToFile

      public static void writeJsonToFile(String jsonString, String filePath) throws IOException
      This method writes JSON String to a JSON file
      Parameters:
      jsonString - JSON String
      filePath - JSON file path
      Throws:
      IOException - throws IOException
    • getElementFromJsonString

      public static String getElementFromJsonString(String jsonString, String elementPath)
      This method reads the value of an element from JSON String using json path
      Parameters:
      jsonString - JSON String
      elementPath - element path to extract value
      Returns:
      String value of element from JSON
    • getElementsFromJsonString

      public static List<String> getElementsFromJsonString(String jsonString, String elementPath)
      This method reads the values from JSON String using JSON path
      Parameters:
      jsonString - JSON String
      elementPath - element path to extract value
      Returns:
      List of String values of elements from JSON
    • getElementsFromJsonString

      public static List<String> getElementsFromJsonString(String jsonString, String... elementPaths)
      This method reads the values of multiple elements from JSON String using JSON path
      Parameters:
      jsonString - JSON String
      elementPaths - element paths
      Returns:
      List of String values of elements from JSON
    • getElementsFromJsonString

      public static Map<String,String> getElementsFromJsonString(String jsonString, Map<String,String> elementPaths)
      This method reads the values of multiple elements from JSON String using JSON path
      Parameters:
      jsonString - JSON String
      elementPaths - element paths
      Returns:
      Map of keys and values from JSON