Related
I just need to query all information of the doctor in the first index.
Here is my sample XML data
Here is my sample JSON data:
Both XML and JSON data are same. I just converted the XML to JSON format.
I have more documents like this.
I tried this query in this image
this query showing all information but I just need first doctors information.
I also tried in command prompt.Here is the query done in cmd
Here is my sample JSON code block: but I have more similar documents
{
"doctors": {
"doctor":[
{
"ssn": "257-79-xxxx",
"name": "Mavis Bxx",
"address": "xxxx Rusk Drive",
"country": "France",
"email": "",
"phone": "",
"patients": {
"patient": [
{
"gender": "Male",
"name": "Itch xxxx",
"address": "xx Cottonwood Avenue",
"revenue": "254",
"_country": "Spain",
"_id": "27"
},
{
"gender": "Male",
"name": "Damon xxxxx",
"address": "xx David Trail",
"revenue": "370",
"_country": "Germany",
"_id": "21"
}
]
},
"_id": "6"
},
{
"ssn": "179-45-xxxx",
"name": "Tobie Conxxxx",
"address": "x Comanche Center",
"country": "Spain",
"email": "tconringh#xxx.xxx",
"phone": "+86 998 262 xxxx",
"patients": {
"patient": {
"gender": "Male",
"name": "Vergil Tome",
"address": "x Melody Drive",
"revenue": "254",
"_country": "Germany",
"_id": "15"
}
},
"_id": "18"
},
{
"ssn": "777-59-xxxx",
"name": "Gertrud Macxxxx",
"address": "x Buell Drive",
"country": "USA",
"email": "gmaclaig2#xxx.com",
"phone": "+62 975 394 xxxx",
"patients": {
"patient": [
{
"gender": "Non-binary",
"name": "Dre Skxxxx",
"address": "x Becker Circle",
"revenue": "400",
"_country": "Germany",
"_id": "20"
},
{
"gender": "Female",
"name": "Arleyne Lestxxxx",
"address": "xx Farragut Court",
"revenue": "225",
"_country": "France",
"_id": "22"
}
]
},
"_id": "3"
}
You needs to change your collect data format. Your current format is single big size data. Not a quarriable format.
So
From current format
{
"doctors": {
"docker": [
{
...
"patients": {
"patient": [
{
...
},
{
...
}
]
},
},
{
...
}
]
}
}
To this format
[
{
...
"patients": [
{
...
},
{
...
}
]
},
{
...
}
]
Test JSON
[
{
"ssn": "2xx-7x-4xxx",
"name": "Mavis Bxxxed",
"address": "9xxx Rusk Drive",
"country": "France",
"email": "",
"phone": "",
"patients": [
{
"gender": "Male",
"name": "Itch Txxx",
"address": "5xx Cottonwood Avenue",
"revenue": "25x",
"_country": "Spain",
"_id": "27"
},
{
"gender": "Male",
"name": "Damon Wxxx",
"address": "09xx Dxxxx Trail",
"revenue": "370",
"_country": "Germany",
"_id": "21"
}
],
"_id": "6"
},
{
"ssn": "19-45-xxxx",
"name": "Tobie Coxxxx",
"address": "8x Comxxxx Center",
"country": "Spain",
"email": "tconxxxxx#usa.gov",
"phone": "",
"patients": [
{
"gender": "Male",
"name": "Some one",
"address": "1 Mexxxx Drive",
"revenue": "254",
"_country": "Germany",
"_id": "15"
}
],
"_id": "18"
}
]
In Compass View after add data upper data
Find doctor by name query
{ name: "Mavis Bxxxed" }
Find doctor by patient name
{ "patients.name": "Some one" }
If same search with this query
{ "patients.name": "Itch Txxx" }
OR
{ "patients.name": "Damon Wxxx" }
will same result to find the first docker (Mavis Bxxxed)
Due to it's patients start [ and end ]. it is array type a single size of data.
You can filter by project option
{
patients: {
$filter:
{
input: "$patients",
cond: { $eq: [ "$$patient.name", "Itch Txxx"] },
as: "patient"
}
}
}
OR shows only address
{ "patients.address" : 1 }
How to write the JSON schema for both of the payloads by combining in a single schema alert_type: "change" with alert_sub_type: "check change"
alert_type: "change" with alert_sub_type: "check change"
{
"alert_details": {
"event_date": "2021-04-26T12:30:80Z",
"camount": "789",
"profile": {
"name": {
"first_name": "xxxx",
"last_name": "xxxx",
"middle_name": "xxx"
}
},
"check_cash_date": "2021-04-26",
"profile_address": {
"name": "xxxxx",
"street_address": "xxxxxx",
"city": "xxxx",
"state": "CA",
"zip_code": "90021"
},
"alert_id": {
"id": "abc123",
"subject": "abc123",
"abc_id": "abc123"
}
},
"alert_sub_type": "check change",
"alert_type": "change",
"provider": "ABCD",
"view_date": "2020-11-03T10:15:30Z",
"status": "Read"
}
alert_type : "review" alert_sub_type: "review check"
{
"alert_details": {
"event_date": "2020-11-03T10:15:30Z",
"account_number": "*********xxx",
"check_start_number": "2",
"myprofile": {
"name": {
"first_name": "xxxx",
"last_name": "xxxx",
"middle_name": "M"
}
},
"order_shipped_date": "2021-04-23",
"myprofile_address": {
"name": "xxxxx",
"street_address": "xxxxx",
"city": "xxxx",
"state": "xxxx",
"zip_code": "90021"
},
"quantity_ordered": "12",
"alert_id": {
"id": "abc123",
"subject": "abc123",
"abc_id": "abc123"
}
},
"alert_sub_type": "review Check",
"alert_type": "review",
"provider": "abcd",
"view_date": "2020-11-03T10:15:30Z",
"status": "Read"
}
in this alert_type: "change" with alert_sub_type: "check change" mandatory fields are
camount: ""
profile: ""
check_cash_date: ""
profile_address_name: ""
in the alert_type : "review" alert_sub_type: "review check"
mandatory fields are :
check_cash_date: ""
myprofile: ""
"quantity_ordered"
I have created a Stage and File Format in Snowflake which works with all my other JSON files except this, which throws an error:
Error parsing JSON: misplaced { File 'rooms.json.gz', line 1,
character 2 Row 0, column $1
I am using the same query that I am using for other files.
SELECT $1
FROM #MySchema.MY_STAGE/rooms.json.gz
;
What is wrong with the structure of this specific JSON file?
{
"rooms": [
{
"area": 131.49,
"longDescription": "",
"dateCreated": 1589908063390,
"reservable": false,
"name": "E249",
"remoteInfo": "",
"description": "",
"id": 2,
"type": {
"hexColor": "c16058",
"contentFlag": 1,
"cost": 0.0,
"dateCreated": 1308610520717,
"color": {},
"name": "BREAK ROOM",
"occupiable": false,
"id": 120,
"parkingSpace": false,
"dateUpdated": 1591818585913,
"typeCode": ""
},
"floor": {
"area": 25312.9878,
"dateCreated": 1589907703870,
"drawingAvailable": true,
"interiorGross": 0.0,
"name": "2",
"leaseArea": 0.0,
"id": 12,
"building": {
"address": {
"country": {
"defaultSelected": true,
"subdivisionCategoryName": "state",
"alpha2Code": "US",
"isoCode": "US",
"name": "United States of America (the)",
"id": 223
},
"city": "Some City",
"street": "Some Drive",
"postalCode": "00000",
"state": {
"country": {
"defaultSelected": true,
"subdivisionCategoryName": "state",
"alpha2Code": "US",
"isoCode": "US",
"name": "United States of America (the)",
"id": 223
},
"defaultSelected": false,
"code": "XX",
"name": "Some State",
"id": 66,
"categoryName": "state"
}
},
"code": "B2",
"dateCreated": 1589907508020,
"metric": false,
"name": "Some name",
"location": {},
"revitLink": "",
"id": 45,
"dateUpdated": 1601315841453,
"costCenters": []
},
"dateUpdated": 1600441936663
},
"capacity": 0,
"dateUpdated": 1600441936960
}
]
}
Edit: Screenshot from Notepad++ with all characters enabled
I want my Woocommerce store connected to a shipping parcel company. There is no existing WooCommerce plugin for it. I want to do it with webhooks, I had already successfully made a POST request to a URL after the order.created action. The JSON output contains all the shipping information. But I want to change the format of the JSON output.
The current JSON output is something like this.
{
"id": 605,
"parent_id": 0,
"status": "pending",
"order_key": "wc_order_5893614a8fb78",
"number": 605,
"currency": "USD",
"version": "2.6.13",
"prices_include_tax": false,
"date_created": "2017-02-02T16:41:46",
"date_modified": "2017-02-02T16:41:46",
"customer_id": 2,
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "13.60",
"shipping_tax": "1.22",
"cart_tax": "1.44",
"total": "32.24",
"total_tax": "2.66",
"billing": {
"first_name": "Damandeep",
"last_name": "Singh",
"company": "",
"address_1": "1257 ",
"address_2": "Coach House Court",
"city": "Fullerton",
"state": "CA",
"postcode": "92831",
"country": "US",
"email": "daman#singhdd.com",
"phone": "(122) 274-5555"
},
"shipping": {
"first_name": "Damandeep",
"last_name": "Singh",
"company": "",
"address_1": "1257",
"address_2": "Coach House Court",
"city": "Fullerton",
"state": "CA",
"postcode": "92831",
"country": "US"
},
"payment_method": "paypal_express",
"payment_method_title": "Paypal Express",
"transaction_id": "",
"customer_ip_address": "103.41.36.35",
"customer_user_agent": "PostmanRuntime/3.0.9",
"created_via": "rest-api",
"customer_note": "",
"date_completed": "2017-02-02T08:41:46",
"date_paid": "",
"cart_hash": "",
"line_items": [
{
"id": 79,
"name": "Kaju Katli",
"sku": "SW-282",
"product_id": 491,
"variation_id": 494,
"quantity": 1,
"tax_class": "",
"price": "15.98",
"subtotal": "15.98",
"subtotal_tax": "1.44",
"total": "15.98",
"total_tax": "1.44",
"taxes": [
{
"id": 1,
"total": 1.4382,
"subtotal": 1.4382
}
],
"meta": [
{
"key": "packing-size",
"label": "Packing Size",
"value": "2lb Box"
}
]
}
],
"tax_lines": [
{
"id": 81,
"rate_code": "SALES TAX-1",
"rate_id": "1",
"label": "Sales Tax",
"compound": false,
"tax_total": "1.44",
"shipping_tax_total": "1.22"
}
],
"shipping_lines": [
{
"id": 80,
"method_title": "USPS Medium Flat Rate Box",
"method_id": "usps_medium_box",
"total": "13.60",
"total_tax": "0.00",
"taxes": []
}
],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "https://ambala.webdemos.cf/wp-json/wc/v1/orders/605"
}
],
"collection": [
{
"href": "https://ambala.webdemos.cf/wp-json/wc/v1/orders"
}
],
"customer": [
{
"href": "https://ambala.webdemos.cf/wp-json/wc/v1/customers/2"
}
]
}
}
The JSON output should be something like this.
{
"name": "Gijs Boersma",
"street": "Lange laan",
"house_number": "29",
"house_number_extension": "a",
"zipcode": "9281EM",
"city": "Zevenaar",
"telephone": "0602938172",
"email": "noreply#example.com",
"reference": "Bestelling 112",
"pick_up_point": {
"uuid": "560db083-d941-425b-b3b6-b813718297e1"
},
"product": "sameday_parcel_medium",
"product_options": [
{
"option": "allow_neighbours",
"value": false
},
{
"option": "require_signature",
"value": false
},
{
"option": "age_check_18",
"value": false
},
{
"option": "perishable",
"value": true,
"max_attempts": 2
}
]
}
you can do this by the orders filter.
add_filter( 'woocommerce_rest_prepare_shop_order_object', 'change_shop_order_response', 10, 3 );
function change_shop_order_response( $response, $item, $request ) {
//Do your stuff here with the $response object.
return $response
}
I have the following sample JSON
"address":{
"details":
[
{
"id" :<system generated UUID>,
"city" :{"type" : "string"},
"country" :{"type" : "string"},
"name" :{"type" : "string"},
"url" :{"type" : "string"},
"contacts" :
[{
"email":{"type" : "string"},
"phone":{"type" : "number"}
}]
}
]
}
I want the data to be in the following ways
Example 1:
"address":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk"
}]
}
Example 2:
"address":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "hari34#gmail.com",
"phone": 6789435634
}
]
}]
}
Example 3 :
"address":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "hari34#gmail.com",
"phone": 6789435634
},
{
"email": "sri123#gmail.com",
"phone": 9876655555
}
]
}]
}
Example 4:
"address":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "hari34#gmail.com",
"phone": 6789435634
}
]
},
{
"id": 3456,
"city": "Texas",
"country": "USA",
"name": "Texas Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "ram123#gmail.com",
"phone": 876543219
}
]
}
]
}
I am very new to n1ql query, would anyone please help me to find the solution for inserting/Update an array to the object with in object. Example 1 is inserting an data to JSON, Example 2 is updating the data to Example 1 and follows...
1. Please help to get n1ql queries that satisfies above examples.
2. How to generate an UUID to id field in the document
1) Appends array never checks if element already exist in the array
INSERT INTO default VALUES ("k01", { "details": [ { "id": 1234, "city": "Medway", "country": "United Kingdom", "name": "Medway Youth Hostel", "url": "http://www.yha.org.uk" }] });
UPDATE default AS d SET e.contact = [ { "email": "hari34#gmail.com", "phone": 6789435634 } ]
FOR e IN d.details WHEN e.id = 1234 END
WHERE META().id = "k01";
UPDATE default AS d SET e.contact = ARRAY_APPEND(e.contact,{ "email": "sri123#gmail.com", "phone": 9876655555 })
FOR e IN d.details WHEN e.id = 1234 END
WHERE META().id = "k01";
UPDATE default AS d SET d.details = ARRAY_APPEND(d.details,{ "id": 3456, "city": "Texas", "country": "USA", "name": "Texas Youth Hostel", "url": "http://www.yha.org.uk", "contact": [ { "email": "ram123#gmail.com", "phone": 876543219 } ] })
WHERE META().id = "k01";
SELECT * from default USE KEYS["k01"];
2) USE UUID() function like below
INSERT INTO default VALUES ("k01", { "details": [ { "id": UUID(), "city": "Medway", "country": "United Kingdom", "name": "Medway Youth Hostel", "url": "http://www.yha.org.uk" }] });