Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Update a field from JSON Object or ObjectNode

Category: Rest Assured

We need to use put() method to update a field value if fieldValue is not another ObjectNode. If fieldValue is an ObjectNode use set() or replace() method.

// To replace a field value, use put() method for non ObjectNode type and replace() or set() for ObjectNode
		employeeInfo.put("firstname", "Swapna");
		employeeInfo.put("firstname", "Nalla");
		String updatedJsonObject = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(employeeInfo);
		System.out.println("After updating field , JSON Object is : \n"+ updatedJsonObject);

Leave a Reply

Your email address will not be published. Required fields are marked *