Reputation: 773
How can I get the value of key organization.email using restassured jsonpath from below json response
{
"organization.email": [
"The organization.email has already been taken."
]
}
This is the Rest assured testng code used.
package com.api.tests;
import org.testng.annotations.Test;
import io.restassured.path.json.JsonPath;
public class JsonTest {
@Test
public void test1() {
String jsonString = "{\r\n"
+ " \"organization.email\": [\r\n"
+ " \"The organization.email has already been taken.\"\r\n"
+ " ]\r\n"
+ "}";
JsonPath jsonPath = JsonPath.from(jsonString);
String value = jsonPath.getString("$['organization.email'][0]");
System.out.println("value is:"+value);
}
}
The value of string variable value is showing as null in ide console. Verified
the json path in many json path online websites and it is correct. But the key value
is printing as null
Upvotes: 1
Views: 839
Reputation: 5917
You can choose one of these below approaches.
jsonPath.getString("'organization.email'[0]");
or
jsonPath.getString("get('organization.email')[0]");
or
jsonPath.getString("getAt('organization.email')[0]");
Upvotes: 2