I'm trying to populate number of tables dynamically by the input I get via JSON in angularJS.
I am perplexed on what to use and how to use since I am a learner in angular.
Would be helpful if anybody could help.
I have this JSON obtained in my script.
{
"took": 167,
"timed_out": false,
"_shards": {
"total": 10,
"successful": 10,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 22.126987,
"hits": [
{
"_type": "data",
"_id": "3423",
"_score": 22.126987,
"_source": {
"mdmId": "45234",
"fullName": "rick j cruz",
"firstName": "rick",
"middleName": "j",
"lastName": "cruz",
"gender": "MALE",
"employeeInd": "N",
"phoneList": [],
"partyAdresses": [
{
"addressType": "home",
"address1": "xxx",
"address2": "yyy",
"city": "SAN JOSE",
"state": "CA",
"zipCode": "zzz"
},
{
"addressType": "mailing",
"address1": "xxx",
"address2": "yyy",
"city": "SAN JOSE",
"state": "CA",
"zipCode": "zzz"
}
],
"policyList": [
{
"agencyCode": "50000",
"agentid": "500",
"sourceSystem": "unit",
"policyNumber": "123",
"policyNumberRaw": "123",
"policyStatus": "CANCELLED",
"roleList": [
{
"roleType": "INSURED",
"roleStatus": "ACTIVE",
},
{
"roleType": "LISTED DRIVER",
"roleStatus": "ACTIVE",
}
]
}
]
}
},
{
"_type": "data",
"_id": "3423",
"_score": 22.126987,
"_source": {
"mdmId": "45234",
"fullName": "rick j cruz",
"firstName": "rick",
"middleName": "j",
"lastName": "cruz",
"gender": "MALE",
"employeeInd": "N",
"phoneList": [],
"partyAdresses": [
{
"addressType": "home",
"address1": "xxx",
"address2": "yyy",
"city": "SAN JOSE",
"state": "CA",
"zipCode": "zzz"
},
{
"addressType": "mailing",
"address1": "xxx",
"address2": "yyy",
"city": "SAN JOSE",
"state": "CA",
"zipCode": "zzz"
}
],
"policyList": [
{
"agencyCode": "50000",
"agentid": "500",
"sourceSystem": "unit",
"policyNumber": "123",
"policyNumberRaw": "123",
"policyStatus": "CANCELLED",
"roleList": [
{
"roleType": "INSURED",
"roleStatus": "ACTIVE",
},
{
"roleType": "LISTED DRIVER",
"roleStatus": "ACTIVE",
}
]
}
]
}
}
]
}
}
I now need to populate two different tables based on the total value, mentioned in the JSON.
In case if the JSON returns 3, 3 tables needs to be populated. Eg: Below format.
Can someone help me with a fiddle or something?
Since you want to render out n "hits" with (I guess) som intensive styling and a lot more info than described, I think you should place it in a small directive :
angular.module('myApp').directive('hitTable', function() {
return {
scope: {
hit: '='
},
templateUrl: 'views/hitTable.html'
}
});
hitTable.html could look like this (based on sample boxes in the question, add more of the info you want rendered and you must do the styling yourself) :
<div>
<div> {{ hit._source.mdmId }}</div> <!-- sample box #1 -->
<div> {{ hit._source.firstName }}, {{ hit._source.lastName }}</div> <!-- sample box #2 -->
<div>
<span ng-repeat="address in hit._source.partyAdresses"> <!-- n of sample box #3 -->
{{ address.address1 }}
{{ address.city }}
{{ address.state }}
</span>
</div>
<div>
Once registered in your app and assuming $scope.data hold the sample JSON above you can do
<div ng-repeat="hit in data.hits.hits">
<hit-table hit="hit"></hit-table>
</div>
In my opinion this is the real power of AngularJS (and its like). With very little effort you can have a rather complex page structure. What you need now is to style each "hit", i.e the content of hitTable.html.
NB: I intentionally forget all about "total" here. The important is the content you want to render out, i.e whats within the JSON.
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 }
Need help on parsing JSON data using VBA-Web tool (https://github.com/VBA-tools/VBA-Web) & VBA-JSON Converter
Here is my sample code that I am able to pull the order using the get method but I stumped on parsing the JSON to get the key, value pair that I want
Sub TestWC()
Dim WoocommerceClient As New WebClient
Dim Client As String
Dim Secret As String
WoocommerceClient.BaseUrl = "https://www.example.com"
Client = "ck"
Secret = "cs"
Dim Request As New WebRequest
Request.Method = Httpget
Request.AddQuerystringParam "consumer_key", Client
Request.AddQuerystringParam "consumer_secret", Secret
Dim Response As WebResponse
Request.Resource = "/wp-json/wc/v3/orders"
Set Response = WoocommerceClient.Execute(Request)
//Response.Data -> Should be equal to the JSON data
Dim test As Object
Set test = JsonConverter.ParseJson(Response.Data)
End Sub
When I run this code it will have a error popup saying object required 424 . I also did another work around where I put into the first cell the whole JSON Data using Sheet1.Range("A1").Value = Response.Content then by pulling the data from the cell into the function
Set test = JsonConverter.ParseJson(Sheet1.Range("A1").Value)
I still get the object required error, here is a Sample JSON format from Woocommerce REST API
"id": 727,
"parent_id": 0,
"number": "727",
"order_key": "wc_order_58d2d042d1d",
"created_via": "rest-api",
"version": "3.0.0",
"status": "processing",
"currency": "USD",
"date_created": "2017-03-22T16:28:02",
"date_created_gmt": "2017-03-22T19:28:02",
"date_modified": "2017-03-22T16:28:08",
"date_modified_gmt": "2017-03-22T19:28:08",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "10.00",
"shipping_tax": "0.00",
"cart_tax": "1.35",
"total": "29.35",
"total_tax": "1.35",
"prices_include_tax": false,
"customer_id": 0,
"customer_ip_address": "",
"customer_user_agent": "",
"customer_note": "",
"billing": {
"first_name": "John",
"last_name": "Doe",
"company": "",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US",
"email": "john.doe#example.com",
"phone": "(555) 555-5555"
},
"shipping": {
"first_name": "John",
"last_name": "Doe",
"company": "",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
},
"payment_method": "bacs",
"payment_method_title": "Direct Bank Transfer",
"transaction_id": "",
"date_paid": "2017-03-22T16:28:08",
"date_paid_gmt": "2017-03-22T19:28:08",
"date_completed": null,
"date_completed_gmt": null,
"cart_hash": "",
"meta_data": [
{
"id": 13106,
"key": "_download_permissions_granted",
"value": "yes"
}
],
"line_items": [
{
"id": 315,
"name": "Woo Single #1",
"product_id": 93,
"variation_id": 0,
"quantity": 2,
"tax_class": "",
"subtotal": "6.00",
"subtotal_tax": "0.45",
"total": "6.00",
"total_tax": "0.45",
"taxes": [
{
"id": 75,
"total": "0.45",
"subtotal": "0.45"
}
],
"meta_data": [],
"sku": "",
"price": 3
},
{
"id": 316,
"name": "Ship Your Idea – Color: Black, Size: M Test",
"product_id": 22,
"variation_id": 23,
"quantity": 1,
"tax_class": "",
"subtotal": "12.00",
"subtotal_tax": "0.90",
"total": "12.00",
"total_tax": "0.90",
"taxes": [
{
"id": 75,
"total": "0.9",
"subtotal": "0.9"
}
],
"meta_data": [
{
"id": 2095,
"key": "pa_color",
"value": "black"
},
{
"id": 2096,
"key": "size",
"value": "M Test"
}
],
"sku": "Bar3",
"price": 12
}
],
"tax_lines": [
{
"id": 318,
"rate_code": "US-CA-STATE TAX",
"rate_id": 75,
"label": "State Tax",
"compound": false,
"tax_total": "1.35",
"shipping_tax_total": "0.00",
"meta_data": []
}
],
"shipping_lines": [
{
"id": 317,
"method_title": "Flat Rate",
"method_id": "flat_rate",
"total": "10.00",
"total_tax": "0.00",
"taxes": [],
"meta_data": []
}
],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v3/orders/727"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v3/orders"
}
]
}
}```
I'm passing JSON
{
"name": "Jo",
"surname": "Sin",
"market": "US",
"date": "2020-07-07T00:00:00",
"contactPerson": {
"name": "Jan Kowalski",
"position": "Nikt",
"address": "ul. Kolorowa 123",
"phone": "736537362",
"fax": "827283738",
"email": "koko#ko.pl"
},
"secondContactPerson": {
"name": "Anna Mark",
"position": "buk",
"address": "ul. Nowowiejska 37a",
"phone": "27637222342",
"fax": "347484748",
"email": "lala#la.pl"
},
"representatives": [
{
"name": "Wojciech Makowski",
"title": "master"
}
],
"customerRepresentatives": [
{
"name": "George Soros",
"title": "bogacz"
}
]
}
templateLoader = jinja2.FileSystemLoader(searchpath="./templates/")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "pdf_template.html"
template = templateEnv.get_template(TEMPLATE_FILE)
html = template.render(context_dict)
to Flask template and I would like to modify it for example from date I would like to get just day and month. I would like to list all representatives and more. How can I achieve it?
Try this:
{{ json.date.strftime('%A') }}
I need to import some JSON data am getting into my database. I'd like to use PowerShell and figured out a little, but I need help getting the final piece together.
How to convert following nested JSON to flat CSV in Powershell?
Following is the JSON data :
$openings = '{"objects": [
{
"id": 136691,
"title": "UX Desginer",
"description": "Hiring a UX Designer for our Front End Team",
"position_type": "full_time",
"is_remote_allowed": false,
"is_archived": false,
"is_private": false,
"state": "Draft",
"location": {
"city": "Bangalore",
"state": "Karnataka",
"zipcode": "560078",
"country": "India"
},
"team": "Front-end Team",
"created_date": 1472804002,
"modified_date": 1472804018,
"application_email": "recruiterbox-dmcc0616#applications.recruiterbox.com",
"hosted_url": "https://recruiterbox.recruiterbox.com/jobs/d933h5yh"
},
{
"id": 136691,
"title": "UX Desginer",
"description": "Hiring a UX Designer for our Front End Team",
"position_type": "full_time",
"is_remote_allowed": false,
"is_archived": false,
"is_private": false,
"state": "Draft",
"location": {
"city": "Bangalore",
"state": "Karnataka",
"zipcode": "560078",
"country": "India"
},
"team": "Front-end Team",
"created_date": 1472804002,
"modified_date": 1472804018,
"application_email": "recruiterbox-dmcc0616#applications.recruiterbox.com",
"hosted_url": "https://recruiterbox.recruiterbox.com/jobs/d933h5yh"
}
],
"meta": {
"total": 1,
"limit": 20,
"offset": 0
}}'
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
}