The below Groovy code produces the result shown under Current Result. How do I customize the JSON output as shown in Expected Output?
def resultset = Sql.newInstance(...).rows('select * from client')
println new JsonBuilder(clients:resultset).toPrettyString()
Current Result
{
"clients": [
{
"ID": 1,
"NAME": "ABC",
"ADDR1": "123 MAIN ST",
"ADDR2": "NEW YORK",
"ZIP": "12345"
},
{
"ID": 2,
"NAME": "XYZ",
"ADDR1": "321 MAIN ST",
"ADDR2": "NEW JERSEY",
"ZIP": "98761"
}
]
}
Do I need to loop through each row and customize?
Expected
{
"clients": [
{
"ID": 1,
"NAME": "ABC",
"CONTACT": {
"ADDR1": "123 MAIN ST",
"ADDR2": "NEW YORK",
"ZIP": "12345"
}
},
{
"ID": 2,
"NAME": "XYZ",
"CONTACT": {
"ADDR1": "321 MAIN ST",
"ADDR2": "NEW JERSEY",
"ZIP": "98761"
}
}
]
}
The code below should work (but I'm not sure cause there's no full example provided):
println new JsonBuilder(clients:resultset.collect {[
ID: it.ID,
NAME: it.NAME,
CONTACT: [
ADDR1: it.ADDR1,
ADDR2: it.ADDR2,
ZIP: it.ZIP,
],
]}).toPrettyString()
Try it and let me know in case of any problems. Do You understand how it works?
Related
I am trying to return the value of "description" in "dependentPreferences" where the response meets two conditions: First, check if the name is "John Smith" and then check if the "image" in preferences equals to "papaya.jpg".
The response body is as follows:
[
{
"id": 1,
"name": "John Smith",
"description": null,
"shortDescription": "No recorded interests.",
"alias": "JS",
"preferences": [
{
"id": 1,
"description": "likes candy and papaya",
"image": "papaya.jpg",
"name": "Papaya",
"dependentPreferences": [
{
"id": 1,
"description": "Fruit must be ripe",
"image": "ripe-papaya.jpg",
"name": "pap"
}
]
}
]
},
{
"id": 2,
"name": "Jane Smith",
"description": null,
"shortDescription": "No recorded interests.",
"alias": "JS",
"preferences": [
{
"id": 1,
"description": "likes candy and papaya",
"image": "papaya.jpg",
"name": "Papaya",
"dependentPreferences": [
{
"id": 1,
"description": "Candy must be Skittles",
"image": "Skittles.jpg",
"name": "skt"
}
]
}
]
}
]
So far, i have tried something like this:
response.jsonPath().getString("find { it.name == 'John Smith' }.preferences.find {it.image == 'papaya.jpg'}.dependentPreferences.description
but it is complaining about the syntax. I know this portion of the code works to find the image:
response.jsonPath().getString("find { it.name == 'John Smith' }.preferences.image
but i am having trouble constructing the second condition. Any help would be appreciated.
Working example here. This works for me:
def endpoint = "http://localhost:3130/ids.json"
def jsonResponse = get(endpoint).then().contentType(ContentType.JSON).extract().response()
def path = jsonResponse.jsonPath()
def result = path.getString("find { it.name == 'John Smith' }.preferences.find {it.image == 'papaya.jpg'}.dependentPreferences.description")
Though to be honest: in the JSON, dependentPreferences is an array of objects, so there is a chance for error if the data is different than presented.
i want to filter the result as the following in mongodb. I use $lookup to populate the result from another collection. Please check my following code
This code below is what i get
{
"_id": "5f3d563122de0730d0f6a754",
"barcode": "1234",
"productname": "Lays Packet",
"brandName": "Lays",
"productSize": "12",
"price": "12",
"quant": "12",
"imageurl": "http://localhost:3000/images/imageurl-1597855281050.jpg",
"remaining": "12",
"creator": "3d943b957fb5db510d824c5cbd6e8f7d",
"__v": 0,
"source": [
{
"_id": "5f3a9bbc325a074240a1a815",
"firstname": "test",
"lastname": "test",
"storename": "test",
"gst": "test",
"phoneNumber": 1,
"email": "1#demo.com",
"address1": "test",
"address2": "test",
"city": "test",
"state": "test",
"country": "test",
"zip": "1",
"password": "1",
"usertype": 3,
"unique_SHOP": "3d943b957fb5db510d824c5cbd6e8f7d",
"__v": 0
}
]
},
How to retrieve only unique_SHOP and zip from source listing.I want result like the one below with one or more fields
{
"_id": "5f3d563122de0730d0f6a754",
"barcode": "1234",
"productname": "Lays Packet",
"brandName": "Lays",
"productSize": "12",
"price": "12",
"quant": "12",
"imageurl": "http://localhost:3000/images/imageurl-1597855281050.jpg",
"remaining": "12",
"creator": "3d943b957fb5db510d824c5cbd6e8f7d",
"__v": 0,
"source": [
{
"zip": "1",
"unique_SHOP": "3d943b957fb5db510d824c5cbd6e8f7d",
}
]
},
The query i use
List.aggregate([
{$match:
{ productname: { $regex: req.params.query,$options: "i" }}
},
{ $lookup:{
from: "suppliers",
localField: "creator",
foreignField: "unique_SHOP",
as: "source"
}
},
])
You can try $lookup with pipeline,
$match condition of creator id
$project to display required fields
{
$lookup: {
from: "suppliers",
as: "source",
let: { creator: "$creator" },
pipeline: [
{
$match: {
$expr: { $eq: ["$$creator", "$_id"] }
}
},
{
$project: {
_id: 0,
zip: 1,
unique_SHOP: 1
}
}
]
}
}
Playground
how to make this data to asc order by user's first name and user's last name.
I got the response, want to sort the records by user's first name but it is taking from creation date I guess when using sort how can I make it base on user's first name and user's last name please guide
{
"response": {
"items": [
{
"_id": "5e71f86bd300b313df52fb2f",
"last_message": {
"text": "Alex",
"users": [
{
"_id": "5e4a8d2d3952132a08ae5764",
"first_name": "zack",
"last_name": "Write"
}
]
},
"texter": [
"alex",
"$0ctg"
],
"title": "New group1",
"group": true,
"members": [
{
"_id": "5e4a8afc3952132a08ae575e",
"first_name": "test3",
"last_name": "test4"
}
],
"managers": [
"5e4a8afc3952132a08ae575e"
],
"member": {
"_id": "5e4a8afc3952132a08ae575e",
"first_name": "test3",
"last_name": "test4"
}
},
{
"_id": "5e4e740f380054797d9db621",
"last_message": {
"text": "",
"users": [
{
"_id": "5e4a8d2d3952132a08ae5764",
"first_name": "yuhan",
"last_name": "jacob"
}
]
},
"texter": [
"",
"",
"",
"",
"",
"new iphone x\n brand new iphone wv wwvqzwzvq had sqswgscq wow you wholeheartedly q \n $600.00",
"helo",
"hello",
"hi"
],
"members": [
{
"_id": "5e4d0973babf2b74ca868f4d",
"first_name": "alex",
"last_name": "hales"
}
],
"managers": [],
"member": {
"_id": "5e4d0973babf2b74ca868f4d",
"first_name": "alex",
"last_name": "hales"
}
}
]
}
}
Tried
{
$sort: {
users: 1,
}
},
doesn't help much
Also if I would like to add two field asc desc order what would be the process in MongoDB
Try this hope this will help you !
{
$sort: { "users.first_name": 1 }
},
Okay I am setting up Partial Payments via the Authorize.net API in order to enable multiple cards to be used to cover a single balance/charge.
I'm assuming thier Partial Auth feature covers my use case, but in testing, there is an issue I can show you using the API live console here: https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card
Go to the link above and authorize partial payments with the request I edited below and you will notice when you press submit you get a splitTenderId:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "5KP3u95bQpv",
"transactionKey": "346HZ32z3fP4hTG2"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "462.25",
"payment": {
"creditCard": {
"cardNumber": "5424000000000015",
"expirationDate": "2020-12",
"cardCode": "999"
}
},
"lineItems": {
"lineItem": {
"itemId": "1",
"name": "vase",
"description": "Cannes logo",
"quantity": "18",
"unitPrice": "45.00"
}
},
"tax": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"duty": {
"amount": "8.55",
"name": "duty name",
"description": "duty description"
},
"shipping": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"poNumber": "456654",
"customer": {
"id": "99999456654"
},
"billTo": {
"firstName": "Ellen",
"lastName": "Johnson",
"company": "Souveniropolis",
"address": "14 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"shipTo": {
"firstName": "China",
"lastName": "Bayles",
"company": "Thyme for Tea",
"address": "12 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"customerIP": "192.168.1.1",
"transactionSettings": {
"setting": [
{
"settingName": "emailCustomer",
"settingValue": "true"
}, {
"settingName": "allowPartialAuth",
"settingValue": "true"
},
]
},
"userFields": {
"userField": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
]
}
}
}
}
This is only successful because the amount is 462.25 as the docs say to use for testing, if I use any other (real) amount the splitTenderId is not there.
Here is a new example request, you can post this again on the link above:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "5KP3u95bQpv",
"transactionKey": "346HZ32z3fP4hTG2"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "462",
"payment": {
"creditCard": {
"cardNumber": "5424000000000015",
"expirationDate": "2020-12",
"cardCode": "999"
}
},
"lineItems": {
"lineItem": {
"itemId": "1",
"name": "vase",
"description": "Cannes logo",
"quantity": "18",
"unitPrice": "45.00"
}
},
"tax": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"duty": {
"amount": "8.55",
"name": "duty name",
"description": "duty description"
},
"shipping": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"poNumber": "456654",
"customer": {
"id": "99999456654"
},
"billTo": {
"firstName": "Ellen",
"lastName": "Johnson",
"company": "Souveniropolis",
"address": "14 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"shipTo": {
"firstName": "China",
"lastName": "Bayles",
"company": "Thyme for Tea",
"address": "12 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"customerIP": "192.168.1.1",
"transactionSettings": {
"setting": [
{
"settingName": "emailCustomer",
"settingValue": "true"
}, {
"settingName": "allowPartialAuth",
"settingValue": "true"
},
]
},
"userFields": {
"userField": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
]
}
}
}
}
And with the 462 amount entered this is no longer a partial auth payment and I no longer get a splitTenderId.
Can someone please help me figure out what is going on?
Through a XMLImport function in Excel I retrieve a JSON set of data. I would like to retrieve a list of ONLY all the names of the pools (in Example below, only 'Men Singles A' and 'Men Singles B').
Because the array of data has different properties called /name I do not know a way to filter out all the /name properties that are part of the /teams property.
[
{
"poolId": 864,
"position": 0,
"name": "Men Singles A",
"totTeams": 7,
"nrPlayersInTeam": 1,
"teams": {
"6453": {
"id": 6453,
"name": "Peter",
{
"id": 3886,
"name": "Peter",
}
]
},
"6501": {
"id": 6501,
"name": "Jack",
"players": [
{
"id": 3912,
"name": "Jack",
}
]
},
}
},
{
"poolId": 865,
"position": 1,
"name": "Men Singles B",
"totTeams": 22,
"nrPlayersInTeam": 1,
"teams": {
"6406": {
"id": 6406,
"name": "John",
"players": [
{
"id": 3844,
"name": "John",
}
]
},
"6408": {
"id": 6408,
"name": "Matthew",
"players": [
{
"id": 3845,
"name": "Matthew",
}
]
},
}
}
]
When trying the following ImportXML function with a Xpath selection, I get a list of all the /name/ properties found in the JSON array.
=IMPORTXML("https://www.tournia.net/api/v2/test/pools?tournamentUrl=test&_format=xml";"//name")
Retrieved List:
Men Singles A
Peter
Peter
Jack
Jack
Men Singles B
John
John
Mtthew
Matthew
What would be the appropriate XPath code to only get a list of all the pool names?