I'm accessing a single model and loading its relation using this code below,
return Application::select('id')->with([
'oneApplicant:id,user_id,first_name,last_name,email',
'oneApplicant.referrer:id,parent_id,first_name,last_name,email',
'oneApplicant.referrer.parent:id,first_name,last_name,email',
])->find($id);
and the response is this
{
"id": 200,
"oneApplicant": [
{
"id": 200,
"userId": 9,
"firstName": "Mac",
"lastName": "Lebsack",
"email": "edicki#example.net",
"referrer": {
"id": 9,
"parentId": 5,
"firstName": "Aurelia",
"lastName": "Boyle",
"email": "uhirthe#example.org",
"parent": {
"id": 5,
"firstName": "Dewitt",
"lastName": "Bednar",
"email": "tluettgen#example.net"
}
}
}
]
}
I wanted to convert the response to something like this (couldn't care less about the other attribute, all I need is first_name, last_name & email )
[
{
"id": 200,
"userId": 9,
"firstName": "Mac",
"lastName": "Lebsack",
"email": "edicki#example.net",
},
{
"id": 9,
"parentId": 5,
"firstName": "Aurelia",
"lastName": "Boyle",
"email": "uhirthe#example.org"
},
{
"id": 5,
"firstName": "Dewitt",
"lastName": "Bednar",
"email": "tluettgen#example.net"
}
]
I was testing with map and transform but it doesn't even work and as I understand with the error, my result is not a collection.
Can someone guide me on how to achieve this,
Thanks
Related
I have a json like this:
{
"firstName": "John",
"lastName": "doe",
"age": 26,
"address": {
"streetAddress": "naist street",
"city": "Nara",
"postalCode": "630-0192"
},
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567-8888"
},
{
"type": "home",
"number": "0123-4567-8910"
}
]
}
And get a json path expression: $.phoneNumbers.*.type
How can I delete the keys by this expression in Go?
For the following response as a form of JSON, I want to extract a particular value on the validating first name.
{
"system": false,
"redirect": false,
"url": "user",
"infinite": false,
"csrf": {
"name": "csrf_token",
"value": "1fc51ba92c87ad1f086195e36a4a6b02"
},
"version": "2.0.1869",
"view": {
"data": {
"items": [
{
"id": null,
"name": "No Workspace",
"users": [
{
"id": "170303",
"account_id": "143003",
"email": "Perfuser554#gmail.com",
"first_name": "Perf-WxC",
"last_name": "Eve-971"
},
{
"id": "170318",
"account_id": "143003",
"user_type_id": "3",
"email": "Perfuser555#gmail.com",
"password_format": "1",
"first_name": "Perf-WMV",
"last_name": "Eve-972"
},
{
"id": "170320",
"account_id": "143003",
"email": "Perfuser556#gmail.com",
"first_name": "Perf-YTC",
"last_name": "Eve-973"
},
{
"id": "170321",
"account_id": "143003",
"email": "Perfuser557#gmail.com",
"first_name": "Perf-ZvF",
"last_name": "Eve-974"
},
{
"id": "170322",
"account_id": "143003",
"email": "Perfuser558#gmail.com",
"first_name": "Perf-WmO",
"last_name": "Eve-975"
}
],
"company_name": "Local host"
}
]
},
"show_nav": true
}
}
I want to extract the id and account_id for a particular user on the basis of first name. For example for Perf-YTC the id is 170320 and account_id is 143003.
Could use the JSON extractor, but dont know the index value mentioned in the image.
You could use the following as a JSON extractor,
$..[?(#.first_name == "Perf-YTC")].id for id and
$..[?(#.first_name == "Perf-YTC")].account_id for account_id
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: PUT http://magento.localhost.com/rest/V1/carts/4/order resulted in a 400 Bad Request response: {"message":"Please specify a shipping method."}
My codes:
$shipBill = '{
"addressInformation": {
"shipping_address": {
"id": 60,
"customer_id": 1,
"region": "Arkansas",
"region_id": 5,
"country_id": "US",
"street": [
"Whitefield,New York"
],
"company": "IBM",
"telephone": "94354545",
"postcode": "234533",
"city": "New York",
"firstname": "test",
"lastname": "test",
"prefix": "address_",
"region_code": "AR"
},
"billing_address": {
"id": 60,
"customer_id": 1,
"region": "Arkansas",
"region_id": 5,
"country_id": "US",
"street": ["Whitefield,New York"],
"company": "IBM",
"telephone": "94354545",
"postcode": "234533",
"city": "New York",
"firstname": "test",
"lastname": "test",
"prefix": "address_",
"region_code": "AR"
},
"shipping_method_code": "flatrate",
"shipping_carrier_code": "flatrate"
}
}';
$checkout = $magento->createShippingAndBilling($quoteId, $shipBill)->getInArray();
$payment = '
{
"paymentMethod": {
"method": "checkmo"
}
}';
$order = $magento->orderCreate($quoteId, $payment)->getInArray();
I have added items on a cart by the rest API. Everything is working only when I tried to place an order I am getting this error.
I have the following structure in RethinkDB
{ "id": "1", "values": [{ "id": 1, "firstname": "foo" }] },
{ "id": "2", "values": [{ "id": 2, "firstname": "bar" }] }
How can I update each "values" array and add an additional property to it?
For instance I'd like to achieve
{ "id": "1", "values": [{ "id": 1, "firstname": "foo", "lastname": null }] },
{ "id": "2", "values": [{ "id": 2, "firstname": "bar", "lastname": null }] }
Something like:
r.table('test').get(id).update(function(row) {
return {values: row('values').map(function(val)
return val.merge({lastname: null});
});
})
This question already has answers here:
Ruby: Easiest Way to Filter Hash Keys?
(14 answers)
Closed 6 years ago.
I am a beginner with Ruby, and I have the following Json array:
"elements": [
{
"type": "Contact",
"id": "1",
"createdAt": "131231235",
"name": "test",
"updatedAt": "1456328049",
"accountName": "Mr Test",
"country": "China",
"firstName": "Test",
"lastName": "lastNameTest",
},
{
"type": "Contact",
"id": "2",
"createdAt": "156453447",
"name": "test2",
"updatedAt": "124464554",
"accountName": "Mr Test2",
"country": "Germany",
"firstName": "Test2",
"lastName": "lastNameTest2",
},...
]
I want to filter out only a few keys + values: for example I want to return only the id,name,accountName,firstname and lastname.
So the exspected output is the following:
"elements": [
{
"id": "1",
"name": "test",
"accountName": "Mr Test",
"firstName": "Test",
"lastName": "lastNameTest",
},
{
"id": "2",
"name": "test2",
"accountName": "Mr Test2",
"firstName": "Test2",
"lastName": "lastNameTest2",
},...
]
I tried the following: create a filter array which has the elements I want to return and then map over the items but then I get stuck..
filters = []
filters.push("accountName")
filters.push("lastName")
filters.push("firstName")
filters.push("Id")
output["elements"].each do |item|
result = []
item.map {|key,value|filters.include? key}
result.push(?)
Thank you for the help.
Check this out, you should be able to work out from this:
output = { "elements": [
{
"id": "1",
"name": "test",
"accountName": "Mr Test",
"firstName": "Test",
"lastName": "lastNameTest",
"somethoong": "sdsad"
},
{
"id": "2",
"name": "test2",
"accountName": "Mr Test2",
"firstName": "Test2",
"lastName": "lastNameTest2"
}
]}
attribs = %w(accountName lastName firstName id)
output[:elements].each do |item|
item.delete_if{|k,v| !attribs.include?(k.to_s)}
end