Package io.github.the_sdet.json
Class JSONUtils
java.lang.Object
io.github.the_sdet.json.JSONUtils
This class handles all JSON related Utilities and Helper methods
- Author:
- Pabitra Swain ([email protected])
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetElementFromJsonString(String jsonString, String elementPath) This method reads the value of an element from JSON String using json pathgetElementsFromJsonString(String jsonString, String elementPath) This method reads the values from JSON String using JSON pathgetElementsFromJsonString(String jsonString, String... elementPaths) This method reads the values of multiple elements from JSON String using JSON pathgetElementsFromJsonString(String jsonString, Map<String, String> elementPaths) This method reads the values of multiple elements from JSON String using JSON pathstatic StringreadJsonFromFile(String filePath) This method reads a JSON file and returns the content as Stringstatic voidwriteJsonToFile(String jsonString, String filePath) This method writes JSON String to a JSON file
-
Constructor Details
-
JSONUtils
public JSONUtils()
-
-
Method Details
-
readJsonFromFile
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
This method writes JSON String to a JSON file- Parameters:
jsonString- JSON StringfilePath- JSON file path- Throws:
IOException- throws IOException
-
getElementFromJsonString
This method reads the value of an element from JSON String using json path- Parameters:
jsonString- JSON StringelementPath- element path to extract value- Returns:
- String value of element from JSON
-
getElementsFromJsonString
This method reads the values from JSON String using JSON path- Parameters:
jsonString- JSON StringelementPath- element path to extract value- Returns:
- List of String values of elements from JSON
-
getElementsFromJsonString
This method reads the values of multiple elements from JSON String using JSON path- Parameters:
jsonString- JSON StringelementPaths- 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 StringelementPaths- element paths- Returns:
- Map of keys and values from JSON
-