Click here if you just want the latest release jar file.
Programming Language: Java 17.0.2
Program Used: Visual Studio Code
Files created:
M2Test.java (Path: src\main\java\org\json\M2Test.java),
Milestone2Tests.java (Path: src\test\java\org\json\junit\Milestone2Tests.java)
Files updated:
XML.java (Path: src\main\java\org\json\XML.java)
When modifying the keys in the client code, you first have to convert the XML file to a JSONObject. After that, you need to traverse through it again using recursion to get all the keys and change them.
When modifying the keys inside the library, you can overload the parse function so that you can pass in a function that can modify the keys. The performance is better because you don't have to traverse again since the modification is done during parsing.
The org.json package can be built from the command line, Maven, and Gradle. The unit tests can be executed from Maven, Gradle, or individually in an IDE e.g. Eclipse.
Building from the command line
Build the class files from the package root directory src/main/java
javac org/json/*.java
Create the jar file in the current directory
jar cf json-java.jar org/json/*.class
Compile a program that uses the jar (see example code below)
javac -cp .;json-java.jar Test.java (Windows)
javac -cp .:json-java.jar Test.java (Unix Systems)
Test file contents
import org.json.JSONObject;
public class Test {
public static void main(String args[]){
JSONObject jo = new JSONObject("{ \"abc\" : \"def\" }");
System.out.println(jo.toString());
}
}
Execute the Test file
java -cp .;json-java.jar Test (Windows)
java -cp .:json-java.jar Test (Unix Systems)
Expected output
{"abc":"def"}
Tools to build the package and execute the unit tests
Execute the test suite with Maven:
mvn clean test
Execute the test suite with Gradlew:
gradlew clean build test