I know that there is a lot of information regarding validations in rest assure but unfortunately I am not able to find exactly the solution to my issue.
I am training to validate the response of the following JSON:
{
"A":[
{
"B":[
{
"C":"c",
"D":"d"
}
],
"E":[
{
"F":[
{
"G":"g1"
}
]
},
{
"F":[
{
"G":"g2"
}
],
},
{
"F":[]
}
]
}
],
"H": "h"
}
with the following code:
response.body("A.E.F.G", hasItems(expectedValues.get(G).toArray(new String[0])))
expectedValues.get(G) return a list of g1 and g2.
the ERROR that I get is:
JSON path A.E.F.G doesn't match.
Expected: an array containing ["g1", "g2"]
Actual: [[[g1], [g2], []]]
How can I get that done?
That solve the problem:
response.body("A.E.F.G.flatten()", hasItems(expectedValues.get(G).toArray(new String[0])))
I would like to convert this JSON
{
"l1k1": {
"l2k1": "l2v1",
"l2k2": 1
},
"l1k2": [
{
"e1l1": "e1v1",
"e1l2": "e1v2"
},
{
"e2l1": "e2v1",
"e2l2": "e2v2"
}
]
}
to this one
{
"papa": {
"l1k1c": {
"l2k1c": {
"string": "l2v1"
},
"l2k2c": {
"int": 1
}
},
"l1k2c": {
"array": [
{
"e1l1": "e1v1",
"e1l2": "e1v2"
},
{
"e2l1": "e2v1",
"e2l2": "e2v2"
}
]
}
}
}
where:
"l" stands for level
"k" for key, "v" for value
"e" for element
"c" for copy (where "*" maps to "*c")
I'm using circe's Json but having a hard time renaming the keys or creating parents or children with it. As I'm writing this, I'm thinking I may need to use its ACursor instead. As you may have guessed, I'm trying to generate an AVRO doc from an input JSON. I'm open to help w/ my approach or any suggestions about how to go about it in a cleaner way.
I want to access the the below JSON payload :
[
{
"ApplicantContactDetail": [
{
"ApplicantBaseDetails": {
"CATEGORY": "P",
"ULN": "1265847478"
} }
]
}
]
and need output as
{
"Number":2,
"Data":
{
"ResidencyCode":"CATEGORY"
}
}
i need to map CATEGORY in the output from liquid template, may i know the correct syntax for this to achieve.
this json formate have basically two array object so i am lit bit confused that how do i iterate these two object and display separately.
[
{
"todays_birthday":[
{
"member_id":"1",
"member_name":"Subhash Chander Chandna",
"member_number":"490",
"member_dob":"1995-06-30"
},
{
"member_id":"4",
"member_name":"Mrs. Bimla Rani",
"member_number":"500",
"member_dob":"1946-06-30"
}
]
},
{
"tommorow_birthday":[
{
"member_id":"3",
"member_name":"Jagdish Kumar Pahuja",
"member_number":"490",
"member_dob":"1946-07-01"
},
{
"member_id":"5",
"member_name":"Raja Ram",
"member_number":"500",
"member_dob":"1946-07-01"
}
]
}
]
I think your json could be formed as an object with two properties (today_birthdays and tomorrow_birthdays) and inside each property you get the array of birthdays.
Like that:
{
today_birthdays: [
//birthdays
],
tomorrow_birthdays: [
//birthdays
]
}
And so you could iterate through the birthdays, for example, with lodash (in JavaScript):
_(obj.today_birthdays).forEach(function(birthday) {
//use birthday var..
}
I want to create a json string for my web application. Actually i am new to this json format.In my json string i have to create two arrays in my json structure.But i have some syntax problem in creating two arrays. my json string is given below for your reference.
{
MarkUpdate:[
{
'FinalMarks':[
{
'studentId':'S1',
'Ques_Mark':[
{
'qId' :'Q1',
'mark':'14',
},
{
'qId':'Q2',
'mark':'10',
}
]
},
{
'studentId':'S2',
'Ques_Mark':[
{
'qId' :'Q1',
'mark':'12',
},
{
'qId':'Q2',
'mark':'13',
}
]
}
]
}
]
}
In my above json string format,my MarkUpdate contains one array object named as FinalMarks.So,here i have to create one more array object named as EvalMarks under MarkUpdate.
Acually my EvalMarks contains following elements...
'EvalMarks':[
{
'EvalId':'E1',
'Ques_Mark':[
{
'qId' :'Q1',
'studId':'S1',
'mark':'13',
},
{
'qId':'Q2',
'studId':'S1',
'mark':'13',
}
]
},
{
'EvalId':'E2',
'Ques_Mark':[
{
'qId' :'Q1',
'studId':'S2',
'mark':'10',
},
{
'qId':'Q2',
'studId':'S2',
'mark':'10',
}
]
}
]
So, i have declare this EvalMarks under the MarkUpdate.I missed the syntax...
Could you plz tell me how to add this array object under the MarkUpdate.
guide me to get out of this issue...
To declare two arrays in one JSON object, remember that the JSON object can only be a single object, therefore the array must be inside the enclosing curly braces. For example:
{
"array1":[1,2,3],
"array2":["jim","louise","mark"]
}
For your case, it's important to remember that you should properly indent your braces, square and curly, so that you can visually identify mistakes before they become problems. I stringly recommend http://jslint.com/ to validate your JSON before using it. It's also great for Javascript:
{
"MarkUpdate":[
{
"FinalMarks":[
{
"studentId":"S1",
"Ques_Mark":[
{
"qId" :"Q1",
"mark":"14"
},
{
"qId":"Q2",
"mark":"10"
}
]
},
{
"studentId":"S2",
"Ques_Mark":[
{
"qId" :"Q1",
"mark":"12"
},
{
"qId":"Q2",
"mark":"13"
}
]
}
]
}
],
"EvalMarks":[
{
"EvalId":"E1",
"Ques_Mark":[
{
"qId" :"Q1",
"studId":"S1",
"mark":"13"
},
{
"qId":"Q2",
"studId":"S1",
"mark":"13"
}
]
},
{
"EvalId":"E2",
"Ques_Mark":[
{
"qId" :"Q1",
"studId":"S2",
"mark":"10"
},
{
"qId":"Q2",
"studId":"S2",
"mark":"10"
}
]
}
]
}
Its not a valid JSON if you have commas after the last key-value pair in an object. I would start by knocking off all those unnecessary commas after the last key-value pairs inside most of your objects and validating the JSON in www.jslint.com
To be more clear ,
{
"qId":"Q2",
"studId":"S2",
"mark":"10",
}
is Not Valid.
On the other hand,
{
"qId":"Q2",
"studId":"S2",
"mark":"10"
}
Is valid.