<dependencies>
<dependency>
<groupId>org.hjson</groupId>
<artifactId>hjson</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
import org.hjson.JsonObject;
import org.hjson.JsonValue;
import org.hjson.JsonArray;
import org.hjson.ParseException;
public class HjsonReader {
public static void main(String[] args) {
try {
JsonObject config = JsonObject.readJSON("config.hjson");
String username = config.getString("username", "");
int port = config.getInt("port", 8080);
JsonArray hosts = config.getArray("hosts", new JsonArray());
System.out.println("Username: " + username);
System.out.println("Port: " + port);
System.out.println("Hosts: " + hosts);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
import org.hjson.JsonObject;
public class HjsonWriter {
public static void main(String[] args) {
JsonObject config = new JsonObject();
config.set("username", "myUsername");
config.set("port", 8081);
config.add("hosts", "localhost");
config.add("hosts", "example.com");
String hjsonString = config.toString();
try {
Files.write(Paths.get("newConfig.hjson"), hjsonString.getBytes());
System.out.println("Hjson file written successfully.");
} catch (IOException e) {
e.printStackTrace();
}
}
}