Java
Chilkat2 Java
JSON PathPrefix Example
Demonstrates the JSON object'sPathPrefix property.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
JsonObject json = new JsonObject();
json.setPathPrefix("company.billing.");
json.updateString("company_name", "TechNova Solutions Inc.");
json.updateString("address_line_1", "123 Innovation Drive");
json.updateString("address_line_2", "Suite 450");
json.updateString("city", "Seattle");
json.updateString("state_province", "WA");
json.updateString("postal_code", "98101");
json.updateString("country", "USA");
json.setEmitCompact(false);
System.out.println(json.emit());
// Result:
// {
// "company": {
// "billing": {
// "company_name": "TechNova Solutions Inc.",
// "address_line_1": "123 Innovation Drive",
// "address_line_2": "Suite 450",
// "city": "Seattle",
// "state_province": "WA",
// "postal_code": "98101",
// "country": "USA"
// }
// }
// }
String city = json.stringOf("city");
System.out.println("city = " + city);
}
}