I am using this api to search jack related data in city los gotas:
https://api.foursquare.com/v2/venues/search?near=los+gatos&query=jack&oauth_token=OUTH_TOKEN&v=20150728&categoryId=4d4b7105d754a06376d81259,4bf58dd8d48988d1fa931735,4bf58dd8d48988d10c941735,4bf58dd8d48988d1ea941735,4bf58dd8d48988d112941735&sortByDistance=1
but it also gives me data those are not relevant to that city. here is the output:
{
"vName": "Jack Barry and Associates",
"vFourSquareID": "4f32c93919836c91c7fa7874",
"enhance": "0",
"vLogo": "",
"bigthumb_logo": "",
"compressthumb_logo": "",
"vBanner": "",
"bigthumb_banner": "",
"compressthumb_banner": "",
"iBarID": "-1",
"tAddress": "Milpitas",
"dLat": "37.425211",
"dLong": "-121.866708",
"distance": "0",
"formatted_address": "2143 Incline Ct,Milpitas, CA 95035"
},
{
"vName": "Jack O'Neill Lounge",
"vFourSquareID": "52df337a498e8f50b076f933",
"enhance": "0",
"vLogo": "",
"bigthumb_logo": "",
"compressthumb_logo": "",
"vBanner": "",
"bigthumb_banner": "",
"compressthumb_banner": "",
"iBarID": "-1",
"tAddress": "Santa Cruz",
"dLat": "36.962198818189",
"dLong": "-122.02405086867",
"distance": "0",
"formatted_address": "Santa Cruz, CA 95060"
},
{
"vName": "Jack Rose Libation House",
"vFourSquareID": "52a5a18511d28dac8af3d02d",
"enhance": "0",
"vLogo": "",
"bigthumb_logo": "",
"compressthumb_logo": "",
"vBanner": "",
"bigthumb_banner": "",
"compressthumb_banner": "",
"iBarID": "-1",
"tAddress": "Los Gatos",
"dLat": "37.240493163257",
"dLong": "-122.00109243393",
"distance": "0",
"formatted_address": "18840 Saratoga Los Gatos Rd (Austin Way),Los Gatos, CA 95030"
}
in the output, first 2 results are not from los gatos city. but still it is displaying. can anyone say why?
You are searching for nearby Los Gatos, but does not specify a range. You should use radius parameter to specify a range. Try following url
https://api.foursquare.com/v2/venues/search?near=Los+Gatos&radius=5000&query=jack&oauth_token=(YOUR_TOKEN)&v=20150728&categoryId=4d4b7105d754a06376d81259,4bf58dd8d48988d1fa931735,4bf58dd8d48988d10c941735,4bf58dd8d48988d1ea941735,4bf58dd8d48988d112941735&sortByDistance=1
Related
I'm trying to update a jsonb array in Postgres by replacing the entire array. It's important to note, I'm not trying to add an array to the object, but simply replace the whole thing with new values. When I try the code below, I get this error in the console
error: cannot replace existing key
I'm using Nodejs as server-side language.
server.js
//new array with new values
var address = {
"appt": appt,
"city": city,
"street": street,
"country": country,
"timezone": timezone,
"coordinates": coordinates,
"door_number": door_number,
"state_province": state_province,
"zip_postal_code": zip_postal_code
}
//query
var text = "UPDATE users SET info = JSONB_insert(info, '{address}', '" + JSON.stringify(address) + "') WHERE id=$1 RETURNING*";
var values = [userid];
//pool...[below]
users table
id(serial | info(jsonb)
And this is the object I need update
{
"dob": "1988-12-29",
"type": "seller",
"email": "eyetrinity3#test.com",
"phone": "5553766962",
"avatar": "f",
"address": [
{
"appt": "",
"city": "Brandon",
"street": "11th Street East",
"country": "Canada",
"timezone": "Eastern Standard Time",
"coordinates": [
"-99.925011",
"49.840649"
],
"door_number": "666",
"state_province": "Manitoba",
"zip_postal_code": "R7A 7B8"
}
],
"last_name": "doe",
"first_name": "john",
"date_created": "2022-11-12T19:44:36.714Z",
}
below works in db-fiddle Postgresql v15 (did not in work in v12)
specific element
update json_update_t set info['address'][0] = '{
"appt": "12",
"city": "crater",
"street": "11th Street East",
"country": "mars",
"timezone": "Eastern Standard Time",
"coordinates": [
"-99.925011",
"49.840649"
],
"door_number": "9999",
"state_province": "marsbar",
"zip_postal_code": "abc 123"
}';
whole array
update json_update_t set info['address'] = '[{
"appt": "14",
"city": "crater",
"street": "11th Street East",
"country": "mars",
"timezone": "Eastern Standard Time",
"coordinates": [
"-99.925011",
"49.840649"
],
"door_number": "9999",
"state_province": "marsbar",
"zip_postal_code": "abc 123"
}]';
I have found the answer for this. Going through some of my older apps I coded, I stumbled upon the answer. It's not JSONB_INSERT but JSONB_SET. Notice the difference. The later will replace the entire key and not insert or add to the object.
JSONB_INSERT --> insert
UPDATE users SET info = JSONB_insert(info, '{address,-1}', '" + JSON.stringify(address) + "',true) WHERE id=$1 RETURNING*
JSONB_SET --> set and replace
UPDATE users SET info = JSONB_SET(info, '{address}', '" + JSON.stringify(address) +"') WHERE id=$1 RETURNING*
We are trying to create a json from a dataframe. Please find the dataframe below,
+----------+--------------------+----------+--------------------+-----------------+--------------------+---------------+--------------------+---------------+--------------------+--------------------+
| CustId| TIN|EntityType| EntityAttributes|AddressPreference| AddressDetails|EmailPreference| EmailDetails|PhonePreference| PhoneDetails| MemberDetails|
+----------+--------------------+----------+--------------------+-----------------+--------------------+---------------+--------------------+---------------+--------------------+--------------------+
|1234567890|XXXXXXXXXXXXXXXXXX...| Person|[{null, PRINCESS,...| Alternate|[{Home, 460 M XXX...| Primary|[{Home, HEREBY...| Alternate|[{Home, {88888888...|[{7777777, 999999...|
|1234567890|XXXXXXXXXXXXXXXXXX...| Person|[{null, PRINCESS,...| Alternate|[{Home, 460 M XXX...| Primary|[{Home, HEREBY...| Primary|[{Home, {88888888...|[{7777777, 999999...|
|1234567890|XXXXXXXXXXXXXXXXXX...| Person|[{null, PRINCESS,...| Primary|[{Home, PO BOX 695020...| Primary|[{Home, HEREBY...| Alternate|[{Home, {88888888...|[{7777777, 999999...|
|1234567890|XXXXXXXXXXXXXXXXXX...| Person|[{null, PRINCESS,...| Primary|[{Home, PO BOX 695020...| Primary|[{Home, HEREBY...| Primary|[{Home, {88888888...|[{7777777, 999999...|
+----------+--------------------+----------+--------------------+-----------------+--------------------+---------------+--------------------+---------------+--------------------+--------------------+
So the initial columns custid, TIN, Entitytype,EntityAttributes will be same for a particular customer, say 1234567890 in our example. But he might be having multiple addresses/phone/email. Could you please help us on how to group them under 1 json.
Expected Structure :
{
"CustId": 1234567890,
"TIN": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"EntityType": "Person",
"EntityAttributes": [
{
"FirstName": "PRINCESS",
"LastName": "XXXXXX",
"BirthDate": "xxxx-xx-xx",
"DeceasedFlag": "False"
}
],
"Address": [
{
"AddressPreference": "Alternate",
"AddressDetails": {
"AddressType": "Home",
"Address1": "460",
"City": "XXXX",
"State": "XXX",
"Zip": "XXXX"
}
},
{
"AddressPreference": "Primary",
"AddressDetails": {
"AddressType": "Home",
"Address1": "PO BOX 695020",
"City": "XXX",
"State": "XXXX",
"Zip": "695020",
}
}
],
"Phone": [
{
"PhonePreference": "Primary",
"PhoneDetails": {
"PhoneType": "Home",
"PhoneNumber": "xxxxx",
"FormatPhoneNumber": "xxxxxx"
}
},
{
"PhonePreference": "Alternate",
"PhoneDetails": {
"PhoneType": "Home",
"PhoneNumber": "xxxx",
"FormatPhoneNumber": "xxxxx"
}
},
{
],
"Email": [
{
"EmailPreference": "Primary",
"EmailDetails": {
"EmailType": "Home",
"EmailAddress": "xxxxxxx#GMAIL.COM"
}
}
],
}
]
}
UPDATE
Tried with the below recommended group by method, it ended up giving 1 customer details, but the email is repeated 4 times in the list. Ideally it should be having only 1 email. Also In the Address Preference Alternate has 1 address and primary has 1 address, but the Alternate shows 2 entries and primary shows 2. Could you please help with an ideal solution.
Probably this should work. id is like a custid in your example which has repeating values.
>>> df.show()
+----+------------+----------+
| id| address| email|
+----+------------+----------+
|1001| address-a| email-a|
|1001| address-b| email-b|
|1002|address-1002|email-1002|
|1003|address-1003|email-1002|
|1002| address-c| email-2|
+----+------------+----------+
Aggregate on those repeating columns and then convert to JSON
>>> results = df.groupBy("id").agg(collect_list("address").alias("address"),collect_list("email").alias("email")).toJSON().collect()
>>> for i in results: print(i)
...
{"id":"1003","address":["address-1003"],"email":["email-1002"]}
{"id":"1002","address":["address-1002","address-c"],"email":["email-1002","email-2"]}
{"id":"1001","address":["address-a","address-b"],"email":["email-a","email-b"]}
I am new to programming and tabulator. I have a PHP page that is displaying my JSON result. I simply want to view this result in a tabulator table on a different page.
The JSON result is formatted like this, it is on a page called proxystatus.php.
{ "0": {
"hostid": "10610",
"proxy_hostid": "10609",
"host": "PIDMPRX-DEV",
"status": "0",
"disable_until": "0",
"error": "",
"available": "1",
"errors_from": "0",
"lastaccess": "0",
"ipmi_authtype": "-1",
"ipmi_privilege": "2",
"ipmi_username": "",
"ipmi_password": "",
"ipmi_disable_until": "0",
"ipmi_available": "0",
"snmp_disable_until": "0",
"snmp_available": "1",
"maintenanceid": "0",
"maintenance_status": "0",
"maintenance_type": "0",
"maintenance_from": "0",
"ipmi_errors_from": "0",
"snmp_errors_from": "0",
"ipmi_error": "",
"snmp_error": "",
"jmx_disable_until": "0",
"jmx_available": "0",
"jmx_errors_from": "0",
"jmx_error": "",
"name": "0955-PIDM-PRX",
"flags": "0",
"templateid": "0",
"description": "0955\ \ Company Name",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"tls_psk_identity": "",
"tls_psk": "",
"proxy_address": "",
"auto_compress": "1"
}}
My tabulator table code is as follows, it is on a page called dash.php
var table = new Tabulator("#proxyStatus", {
height:"100%",
layout:"fitColumns",
placeholder:"Gathering Proxy Status...",
data:'<?=$proxyStatus?>',
columns:[
{title:"Status", field:"status", sorter:"string", width:200},
{title:"Available", field:"available", sorter:"number", formatter:"progress"},
{title:"Last Access", field:"lastaccess", sorter:"string"},
{title:"Name", field:"name", formatter:"star", align:"center", width:100},
{title:"Maintenance Status", field:"maintenance_status", sorter:"string", sortable:false},
{title:"Maintenance Type", field:"maintenance_type", sorter:"date", align:"center"},
{title:"Maintenance ID", field:"maintenanceid", align:"center", formatter:"tickCross", sorter:"boolean"},
],
});
You should add all the columns in the columns array or just use autoColumns:true in the Constructor as mentioned here i made this Jsfiddle for you to understand
const table = new Tabulator("#example-table", {
height: 205, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
data: tabledata1, //assign data to table
layout: "fitData", //fit columns to width of table (optional)
autoColumns: true,
});
I have an object stored in arangodb which has additional inner objects, my current use case requires that I update just one of the elements.
Store Object
{
"status": "Active",
"physicalCode": "99999",
"postalCode": "999999",
"tradingCurrency": "USD",
"taxRate": "14",
"priceVatInclusive": "No",
"type": "eCommerce",
"name": "John and Sons inc",
"description": "John and Sons inc",
"createdDate": "2015-05-25T11:04:14+0200",
"modifiedDate": "2015-05-25T11:04:14+0200",
"physicalAddress": "Corner moon and space 9 station",
"postalAddress": "PO Box 44757553",
"physicalCountry": "Mars Sector 9",
"postalCountry": "Mars Sector 9",
"createdBy": "john.doe",
"modifiedBy": "john.doe",
"users": [
{
"id": "577458630580",
"username": "john.doe"
}
],
"products": [
{
"sellingPrice": "95.00",
"inStock": "10",
"name": "School Shirt Green",
"code": "SKITO2939999995",
"warehouseId": "723468998682"
},
{
"sellingPrice": "95.00",
"inStock": "5",
"name": "School Shirt Red",
"code": "SKITO245454949495",
"warehouseId": "723468998682"
},
{
"sellingPrice": "95.00",
"inStock": "10",
"discount": "5%",
"name": "School Shirt Blue",
"code": "SKITO293949495",
"warehouseId": "723468998682"
}
]
}
I want to change just one of the products stock value
{
"sellingPrice": "95.00",
"inStock": "10",
"discount": "5%",
"name": "School Shirt Blue",
"code": "SKITO293949495",
"warehouseId": "723468998682"
}
Like update store product stock less 1 where store id = x, something to this effect
FOR store IN stores
FILTER store._key == "837108415472"
FOR product IN store.products
FILTER product.code == "SKITO293949495"
UPDATE product WITH { inStock: (product.inStock - 1) } IN store.products
Apart from the above possibly it makes sense to store product as a separate document in collection store_products. I believe in NOSQL that is the best approach to reduce document size.
Found answer
here arangodb-aql-update-single-object-in-embedded-array and there
arangodb-aql-update-for-internal-field-of-object
I however believe it is best to maintain separate documents and rather use joins when retrieving. Updates easily
I am using Liferay for user management and an external application that communicates with Liferay using JSON Web services. When I call the web service /user/get-user-by-id
{
"agreedToTermsOfUse": false,
"comments": "",
"companyId": 10153,
"contactId": 16003,
"createDate": 1390552990000,
"defaultUser": false,
"emailAddress": "basketball#liferay.com",
"emailAddressVerified": false,
"facebookId": 0,
"failedLoginAttempts": 0,
"firstName": "Basketball1",
"graceLoginCount": 0,
"greeting": "Welcome Basketball1!",
"jobTitle": "",
"languageId": "en_US",
"lastFailedLoginDate": null,
"lastLoginDate": null,
"lastLoginIP": "",
"lastName": "",
"ldapServerId": -1,
"lockout": false,
"lockoutDate": null,
"loginDate": null,
"loginIP": "",
"middleName": "",
"modifiedDate": 1390992862465,
"openId": "",
"portraitId": 18708,
"reminderQueryAnswer": "",
"reminderQueryQuestion": "",
"screenName": "basketball1",
"status": 0,
"timeZoneId": "Europe/Paris",
"userId": 16002,
"uuid": "3ce789e0-4cb5-45bf-b57e-68c44ea3ec04"
}
And some information as birthday is missed. I see that also I can change the birthday using the web services /user/update-user but I cannot retrieve the original value. How can I get the birthday information? Is there any other method to obtain the missing data?
And... if I want to update any field of the user and in /user/update-user I MUST put the birthday and I cannot retrieve the old value... the birthday will be lost!
You can get the user birthday through contact service:
http://localhost:8080/api/jsonws/contact/get-contact/contact-id/10202
where id is the user-id