Deserializing a stream of JSON Output - javascript

I am using an API that provides the output in JSON format and I am sure about the fields that it contains. I want to deserialize it into a list format.
I went through the Newtonsoft.Json namespace but didn't get much help. The following article was good but it didn't serve my purpose as I am not aware of the key/value pairs.
Article: http://www.newtonsoft.com/json/help/html/deserializeobject.htm
My code:
static void GetShares()
{
WebRequest request = WebRequest.Create("https://shares.ppe.datatransfer.microsoft.com/api/v1/data/shares/");
request.Method = "GET";
request.Headers.Add("Authorization","Basic "+
Convert.ToBase64String(
Encoding.ASCII.GetBytes("useridandpassword")));
request.ContentType = "application/json";
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
}

I have executed your code and it seems that it is returning and printing the following data on console(not in readable format(indented)).
[
{
"browse_count": 0,
"bytes_free_string": null,
"bytes_total_string": null,
"bytes_unknown": true,
"comment_added_at": null,
"content_added_at": null,
"created_at": "2016-06-09T17:23:53-07:00",
"directory": "/",
"error_bytes_free_size": null,
"error_percent_free": null,
"home_share": false,
"id": 63,
"name": "linuxServerRoot",
"node_id": 5,
"percent_free": null,
"status": null,
"status_at": "2016-12-06T21:24:26-08:00",
"status_message": null,
"updated_at": "2016-12-06T21:24:26-08:00",
"warn_bytes_free_size": null,
"warn_percent_free": null
},
{
"browse_count": 6,
"bytes_free_string": null,
"bytes_total_string": null,
"bytes_unknown": true,
"comment_added_at": null,
"content_added_at": null,
"created_at": "2016-10-17T14:52:06-07:00",
"directory": "/Windows_RTM",
"error_bytes_free_size": null,
"error_percent_free": null,
"home_share": false,
"id": 584,
"name": "Windows_RTM1.1",
"node_id": 7,
"percent_free": null,
"status": null,
"status_at": "2016-12-06T21:24:33-08:00",
"status_message": null,
"updated_at": "2016-12-06T21:24:33-08:00",
"warn_bytes_free_size": null,
"warn_percent_free": null
},
{
"browse_count": 3,
"bytes_free_string": null,
"bytes_total_string": null,
"bytes_unknown": true,
"comment_added_at": null,
"content_added_at": null,
"created_at": "2016-11-29T00:40:20-08:00",
"directory": "/Stats_subscription-For-Demo-Do not delete/WUS-Stats_subscription--Default no stats",
"error_bytes_free_size": null,
"error_percent_free": null,
"home_share": false,
"id": 1401,
"name": "WUS-Stats_subscription--Default no stats",
"node_id": 5,
"percent_free": null,
"status": null,
"status_at": "2016-12-06T21:24:27-08:00",
"status_message": null,
"updated_at": "2016-12-06T21:24:27-08:00",
"warn_bytes_free_size": null,
"warn_percent_free": null
},
{
"browse_count": 0,
"bytes_free_string": null,
"bytes_total_string": null,
"bytes_unknown": true,
"comment_added_at": null,
"content_added_at": null,
"created_at": "2016-11-29T01:06:20-08:00",
"directory": "/Stats_subscription-For-Demo-Do not delete/WUS-Stats_subscription-EyeBall",
"error_bytes_free_size": null,
"error_percent_free": null,
"home_share": false,
"id": 1408,
"name": "WUS-Stats_subscription-EyeBall",
"node_id": 5,
"percent_free": null,
"status": null,
"status_at": "2016-12-06T21:24:28-08:00",
"status_message": null,
"updated_at": "2016-12-06T21:24:28-08:00",
"warn_bytes_free_size": null,
"warn_percent_free": null
},
{
"browse_count": 0,
"bytes_free_string": null,
"bytes_total_string": null,
"bytes_unknown": true,
"comment_added_at": null,
"content_added_at": null,
"created_at": "2016-11-29T01:06:50-08:00",
"directory": "/Stats_subscription-For-Demo-Do not delete/WUS-Stats_subscription-Goku",
"error_bytes_free_size": null,
"error_percent_free": null,
"home_share": false,
"id": 1409,
"name": "WUS-Stats_subscription-Goku",
"node_id": 5,
"percent_free": null,
"status": null,
"status_at": "2016-12-06T21:24:29-08:00",
"status_message": null,
"updated_at": "2016-12-06T21:24:29-08:00",
"warn_bytes_free_size": null,
"warn_percent_free": null
},
{
"browse_count": 0,
"bytes_free_string": null,
"bytes_total_string": null,
"bytes_unknown": true,
"comment_added_at": null,
"content_added_at": null,
"created_at": "2016-11-29T01:07:18-08:00",
"directory": "/Stats_subscription-For-Demo-Do not delete/WUS-Stats_subscription-Cybersecurity",
"error_bytes_free_size": null,
"error_percent_free": null,
"home_share": false,
"id": 1410,
"name": "WUS-Stats_subscription-Cybersecurity",
"node_id": 5,
"percent_free": null,
"status": null,
"status_at": "2016-12-06T21:24:30-08:00",
"status_message": null,
"updated_at": "2016-12-06T21:24:30-08:00",
"warn_bytes_free_size": null,
"warn_percent_free": null
},
{
"browse_count": 0,
"bytes_free_string": null,
"bytes_total_string": null,
"bytes_unknown": true,
"comment_added_at": null,
"content_added_at": null,
"created_at": "2016-11-29T01:08:00-08:00",
"directory": "/Stats_subscription-For-Demo-Do not delete/WUS-Stats_subscription-Feature_Phones_Dubai SOR",
"error_bytes_free_size": null,
"error_percent_free": null,
"home_share": false,
"id": 1411,
"name": "WUS-Stats_subscription-Feature_Phones_Dubai SOR",
"node_id": 5,
"percent_free": null,
"status": null,
"status_at": "2016-12-06T21:24:31-08:00",
"status_message": null,
"updated_at": "2016-12-06T21:24:31-08:00",
"warn_bytes_free_size": null,
"warn_percent_free": null
},
{
"browse_count": 0,
"bytes_free_string": null,
"bytes_total_string": null,
"bytes_unknown": true,
"comment_added_at": null,
"content_added_at": null,
"created_at": "2016-11-29T01:10:47-08:00",
"directory": "/Stats_subscription-For-Demo-Do not delete/WUS-Stats_subscription-Nimbus",
"error_bytes_free_size": null,
"error_percent_free": null,
"home_share": false,
"id": 1412,
"name": "WUS-Stats_subscription-Nimbus",
"node_id": 5,
"percent_free": null,
"status": null,
"status_at": "2016-12-06T21:24:32-08:00",
"status_message": null,
"updated_at": "2016-12-06T21:24:32-08:00",
"warn_bytes_free_size": null,
"warn_percent_free": null
},
{
"browse_count": 0,
"bytes_free_string": null,
"bytes_total_string": null,
"bytes_unknown": true,
"comment_added_at": null,
"content_added_at": null,
"created_at": "2016-11-30T15:49:52-08:00",
"directory": "/EPRS-Connect/HK-EPRS-NVIDIA",
"error_bytes_free_size": null,
"error_percent_free": null,
"home_share": false,
"id": 1467,
"name": "HK-EPRS-NVIDIA",
"node_id": 7,
"percent_free": null,
"status": null,
"status_at": "2016-12-06T21:24:34-08:00",
"status_message": null,
"updated_at": "2016-12-06T21:24:34-08:00",
"warn_bytes_free_size": null,
"warn_percent_free": null
}
]
And You asked to deserialize it in readable format. From this statement i think you want to print/show it on the console in readable format.
To achieve this you can make use of Newtonsoft.Jsonlibrary all you have to add the Json.NET nuget package to your project and following code just before the Console.WriteLine(responseFromServer); statement.
JToken jsonToken = JToken.Parse(responseFromServer);
responseFromServer = jsonToken.ToString(Newtonsoft.Json.Formatting.Indented);
This will print / show the JSON on console window in readable format.

This should do it:
WebRequest request = WebRequest.Create("https://shares.ppe.datatransfer.microsoft.com/api/v1/data/shares/");
request.Method = "GET";
request.Headers.Add("Authorization", "Basic " +
Convert.ToBase64String(
Encoding.ASCII.GetBytes("userid:password")));
request.ContentType = "application/json";
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
JArray items = JArray.Parse(responseFromServer);
Console.WriteLine($"{"Keys".PadRight(24)}Values");
Console.WriteLine($"{"".PadRight(50, '-')}");
foreach (JToken token in items)
{
Dictionary<string, string> dictionary = token.ToObject<Dictionary<string, string>>();
int length = 28;
foreach (var property in dictionary)
{
Console.WriteLine($"{property.Key.PadRight(length)}{property.Value}");
}
Console.WriteLine($"----------------------");
}
This parses the payload as a JArray, grabs the first item (check for null first), deserialises it into a dictionary and selects the keys. I picked 24 as it's the longest key length. You could make the padding variable by using this code.

Related

Javascript in n8n: combine 2 JSON arrays into one structure

In a project I pull JSON-objects out of the Zammad-API.
I get the ticket:
[
{
"id": 53,
"group_id": 2,
"priority_id": 2,
"state_id": 2,
"organization_id": null,
"number": "740534",
"title": "Testanfrage Weichinger",
"owner_id": 3,
"customer_id": 3,
"note": null,
"first_response_at": "2022-11-15T07:19:04.078Z",
"first_response_escalation_at": null,
"first_response_in_min": 0,
"first_response_diff_in_min": 4320,
"close_at": null,
"close_escalation_at": null,
"close_in_min": null,
"close_diff_in_min": null,
"update_escalation_at": null,
"update_in_min": null,
"update_diff_in_min": null,
"last_contact_at": "2022-11-15T07:20:05.013Z",
"last_contact_agent_at": "2022-11-15T07:19:41.008Z",
"last_contact_customer_at": "2022-11-15T07:20:05.013Z",
"last_owner_update_at": "2022-11-15T12:08:48.875Z",
"create_article_type_id": 1,
"create_article_sender_id": 1,
"article_count": 3,
"escalation_at": null,
"pending_time": null,
"type": null,
"time_unit": null,
"preferences": {
"channel_id": 3,
"escalation_calculation": {
"first_response_at": "2022-11-15T07:19:04.078Z",
"last_update_at": "2022-11-15T07:20:05.013Z",
"last_contact_at": "2022-11-15T07:20:05.013Z",
"sla_id": 2,
"sla_updated_at": "2023-01-11T16:02:47.791Z",
"calendar_id": 2,
"calendar_updated_at": "2023-01-15T13:20:30.043Z",
"escalation_disabled": false
}
},
"updated_by_id": 3,
"created_by_id": 3,
"created_at": "2022-11-15T07:19:04.022Z",
"updated_at": "2023-01-16T07:40:29.206Z",
"last_close_at": null
}
]
and the ticket-articles belonging to that ticket:
[
{
"id": 130,
"ticket_id": 53,
"type_id": 1,
"sender_id": 1,
"from": "Stefan Weichinger <office#my.tld>",
"to": "info#company1.com",
"cc": null,
"subject": "Testanfrage Weichinger",
"reply_to": null,
"message_id": "<76d10a5b-64eb-7bfa-98c3-e31ed062802e#my.tld>",
"message_id_md5": "2bf547f5f570f6a8143ca8084110aee2",
"in_reply_to": null,
"content_type": "text/plain",
"references": null,
"body": "\nZum Test von Zammad-Emailing.\n\n-- \nViele Grüße | Stefan Weichinger | DW: | Mobil: \n",
"internal": false,
"preferences": {
"send-auto-response": true,
"is-auto-response": false
},
"updated_by_id": 3,
"created_by_id": 3,
"origin_by_id": null,
"created_at": "2022-11-15T07:19:04.078Z",
"updated_at": "2022-11-15T07:19:04.078Z",
"attachments": [],
"type": "email",
"sender": "Agent",
"created_by": "office#my.tld",
"updated_by": "office#my.tld"
},
{
"id": 131,
"ticket_id": 53,
"type_id": 1,
"sender_id": 1,
"from": "\"Stefan White via company1 Support\" <info#company1.com>",
"to": "office#my.tld",
"cc": "",
"subject": "Testanfrage Weichinger",
"reply_to": null,
"message_id": "<20221115071941.53.6087c1df-aa4c-4cbf-b79a-e2498239612b#ticket.company1.com>",
"message_id_md5": "07a9eee59e351c3d068badce3a56c7a0",
"in_reply_to": "<76d10a5b-64eb-7bfa-98c3-e31ed062802e#my.tld>",
"content_type": "text/html",
"references": null,
"body": "KLappt nun das ANtworten?<br><br><div data-signature=\"true\" data-signature-id=\"1\"> Stefan White<br><br>--<br> Super Support - Waterford Business Park<br> 5201 Blue Lagoon Drive - 8th Floor & 9th Floor - Miami, 33126 USA<br> Email: hot#example.com - Web: http://www.example.com/<br>--</div>",
"internal": false,
"preferences": {
"subtype": "reply",
"email_address_id": 1,
"delivery_retry": 1,
"delivery_channel_id": 3,
"delivery_status_message": null,
"delivery_status": "success",
"delivery_status_date": "2022-11-15T07:19:43.621Z"
},
"updated_by_id": 4,
"created_by_id": 4,
"origin_by_id": null,
"created_at": "2022-11-15T07:19:41.008Z",
"updated_at": "2022-11-15T07:19:43.622Z",
"attachments": [],
"type": "email",
"sender": "Agent",
"created_by": "sel#stefanwhite.com",
"updated_by": "sel#stefanwhite.com"
}
]
A freelancer has written a piece of nodejs that I can call via http-request.
That code needs both JSON-objects combined in one "body", like in:
{
"Ticket": {
"id": 53,
"group_id": 2,
"priority_id": 2,
"state_id": 2,
"organization_id": null,
"number": "740534",
"title": "Testanfrage Weichinger",
"owner_id": 3,
"customer_id": 3,
"note": null,
"first_response_at": "2022-11-15T07:19:04.078Z",
"first_response_escalation_at": null,
"first_response_in_min": 0,
"first_response_diff_in_min": 4320,
"close_at": null,
"close_escalation_at": null,
"close_in_min": null,
"close_diff_in_min": null,
"update_escalation_at": null,
"update_in_min": null,
"update_diff_in_min": null,
"last_contact_at": "2022-11-15T07:20:05.013Z",
"last_contact_agent_at": "2022-11-15T07:19:41.008Z",
"last_contact_customer_at": "2022-11-15T07:20:05.013Z",
"last_owner_update_at": "2022-11-15T12:08:48.875Z",
"create_article_type_id": 1,
"create_article_sender_id": 1,
"article_count": 3,
"escalation_at": null,
"pending_time": null,
"type": null,
"time_unit": null,
"preferences": {
"channel_id": 3,
"escalation_calculation": {
"first_response_at": "2022-11-15T07:19:04.078Z",
"last_update_at": "2022-11-15T07:20:05.013Z",
"last_contact_at": "2022-11-15T07:20:05.013Z",
"sla_id": 2,
"sla_updated_at": "2023-01-11T16:02:47.791Z",
"calendar_id": 2,
"calendar_updated_at": "2023-01-15T13:20:30.043Z",
"escalation_disabled": false
}
},
"updated_by_id": 3,
"created_by_id": 3,
"created_at": "2022-11-15T07:19:04.022Z",
"updated_at": "2023-01-16T07:40:29.206Z",
"datev_dokumentennummer": "",
"last_close_at": null
},
"articles": [
{
"id": 130,
"ticket_id": 53,
"type_id": 1,
"sender_id": 1,
"from": "Stefan Weichinger <office#my.tld>",
"to": "info#company1.com",
"cc": null,
"subject": "Testanfrage Weichinger",
"reply_to": null,
"message_id": "<76d10a5b-64eb-7bfa-98c3-e31ed062802e#my.tld>",
"message_id_md5": "2bf547f5f570f6a8143ca8084110aee2",
"in_reply_to": null,
"content_type": "text/plain",
"references": null,
"body": "\nZum Test von Zammad-Emailing.\n\n-- \nViele Grüße | Stefan Weichinger | DW: | Mobil: \n",
"internal": false,
"preferences": {
"send-auto-response": true,
"is-auto-response": false
},
"updated_by_id": 3,
"created_by_id": 3,
"origin_by_id": null,
"created_at": "2022-11-15T07:19:04.078Z",
"updated_at": "2022-11-15T07:19:04.078Z",
"attachments": [],
"type": "email",
"sender": "Agent",
"created_by": "office#my.tld",
"updated_by": "office#my.tld"
},
{
"id": 131,
"ticket_id": 53,
"type_id": 1,
"sender_id": 1,
"from": "\"Stefan White via company1 Support\" <info#company1.com>",
"to": "office#my.tld",
"cc": "",
"subject": "Testanfrage Weichinger",
"reply_to": null,
"message_id": "<20221115071941.53.6087c1df-aa4c-4cbf-b79a-e2498239612b#ticket.company1.com>",
"message_id_md5": "07a9eee59e351c3d068badce3a56c7a0",
"in_reply_to": "<76d10a5b-64eb-7bfa-98c3-e31ed062802e#my.tld>",
"content_type": "text/html",
"references": null,
"body": "KLappt nun das ANtworten?<br><br><div data-signature=\"true\" data-signature-id=\"1\"> Stefan White<br><br>--<br> Super Support - Waterford Business Park<br> 5201 Blue Lagoon Drive - 8th Floor & 9th Floor - Miami, 33126 USA<br> Email: hot#example.com - Web: http://www.example.com/<br>--</div>",
"internal": false,
"preferences": {
"subtype": "reply",
"email_address_id": 1,
"delivery_retry": 1,
"delivery_channel_id": 3,
"delivery_status_message": null,
"delivery_status": "success",
"delivery_status_date": "2022-11-15T07:19:43.621Z"
},
"updated_by_id": 4,
"created_by_id": 4,
"origin_by_id": null,
"created_at": "2022-11-15T07:19:41.008Z",
"updated_at": "2022-11-15T07:19:43.622Z",
"attachments": [],
"type": "email",
"sender": "Agent",
"created_by": "sel#stefanwhite.com",
"updated_by": "sel#stefanwhite.com"
}
]
}
In my n8n-workflow I can add js-code to do that, could someone help me writing this?
I googled around merging and concatenating json, but the additional adding of the "names" makes it harder for me (adding "Ticket:" and "articles:" ...). I am not a js-coder at all ... so far ;-)
Any help appreciated! thanks
Assuming you have your tickets stored in some variable named tickets and all your articles stored in some variable named articles. You can simply map your tickets to your new combined type as such.
let cominedTickes = tickets.map(ticket => ({
Ticket: ticket,
articles: articles.filter(article => article.ticket_id === ticket.id)
}));
You can simply filter the articles for each ticket by the ticket_id.

how can i store data in txt file using JavaScript and retrieve data

hi im building application and i need to store data in txt file and retrieve it
the data is object like this .. .
[
{
"key": 0,
"id": 1,
"number": "1001",
"name": "سلعة ملموسة",
"offer_end_date": null,
"offer_start_date": null,
"components": [],
"quantity": "9",
"product": {
"id": 1,
"name": "سلعة ملموسة",
"number": "1001",
"product_id": null,
"foreign_name": "Product",
"can_be_sold": 1,
"can_be_purchased": 1,
"can_be_rented": 1,
"available_on_pos": 1,
"pos_quick_lunch": 1,
"available_on_manufacture": 1,
"product_category_id": 1,
"product_unit_type_id": null,
"location_id": null,
"area_id": null,
"discount_value": 10,
"balance": null,
"smallest_unit_id": 1,
"smallest_unit_barcode": null,
"smallest_unit_selling_price": 10,
"smallest_unit_cost": null,
"smallest_unit_selling_price_above": null,
"smallest_unit_selling_price_above_price": null,
"tax_value": 16,
"state_id": 1,
"warehouse_id": null,
"product_type_id": 1,
"product_policy_id": null,
"tax_user_id": null,
"user_id": null,
"get_specification_on_lines": null,
"is_products_has_expire_date": 1,
"is_products_has_patch_number": 1,
"is_products_has_serial_number": 1,
"offer_end_date": null,
"offer_start_date": null,
"last_purchase_date": null,
"last_purchase_purchase": null,
"last_purchase_price": null,
"last_purchase_discount": null,
"created_by": null,
"deleted_by": null,
"approved_by": null,
"approved_date": null,
"approved_state_id": null,
"note": null,
"created_at": "2022-03-04T06:52:16.000000Z",
"updated_at": "2022-03-04T06:52:16.000000Z",
"deleted_at": null,
"get_pos_product_componentss": [],
"get_pos_product_components": [],
"get_smallest_unit_id": {
"id": 1,
"name": "حبة",
"foreign_name": "unit",
"number": "1",
"created_by": 1,
"deleted_by": null,
"approved_by": null,
"approved_date": null,
"approved_state_id": null,
"note": null,
"created_at": "2022-03-04T06:52:15.000000Z",
"updated_at": "2022-03-04T06:52:15.000000Z",
"deleted_at": null
},
"get_product_offers": []
},
"smallest_unit_selling_price": 10,
"smallest_unit_selling_price_above": null,
"smallest_unit_selling_price_above_price": null,
"discount": 0,
"allowed_discount": 10,
"tax_value": 16,
"unit": "حبة",
"smallest_unit_id": 1,
"note": null,
"active": 1,
"price": 104.39999999999999
}
]
now this object i need to store it in file called text.txt
how can i store the object inside the file ..
and how can i retrieve the data using JavaScript ..
thanks ..
ive found solutions thats i can put the object in cookies but my problem with cookies they only allowing 4kb of data
never mind i found this solution ..
first of store data in localStorage like this ..
localStorage.setItem("orders", JSON.stringify(this.orders));
then access it like this ..
var orders = JSON.parse(localStorage.getItem('orders'));
console.log(orders);

Find all occurrences of JSON element using jQuery

How can you parse out all the values for a particular data point within a complex json response form a rest service call?
Here is my JQUERY code to get the rest service json response. I am looking to get all occurrences of "Id" for all "Approver" elements found in the json data and add them to delimited list - preferably using a
;
to separate each "Id"
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script><script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type: 'GET',
url: 'MySite/Change/Request/12345/Approvals/GetApprovalGroupUsers?changeNumber=98765',
data: { get_param: 'value' },
dataType: 'json',
success: function (data) {
$.each(data, function(index, element) {
$('body').append($('<div>', {
text: element.Id
}));
});
}
});
});
});
</script>
</head>
<body>
<button>Click me to get listing of Id's</button>
</body>
</html>
The json data from the service in such:
{
"ApprovalSession": "3ebd4e73-7fc5-4113-9ccd-18833318ee09",
"LoadStatus": 0,
"Index": 0,
"ApprovalId": 0,
"Type": null,
"Approver": null,
"ApproverDisplay": null,
"Status": null,
"CreatedBy": null,
"CanBeRemoved": false,
"ConfigurationItems": [
"cigs01e4a002( OPERATING SYSTEM )",
"cigs01e4a002( OPERATING SYSTEM )",
"cigs01e4a004( OPERATING SYSTEM )",
"cigs01e4a004( OPERATING SYSTEM )"
],
"ApprovalReasons": [
{
"AssociatedCI": "abc4a002( OPERATING SYSTEM )",
"AssociatedRuleName": "Default Impact",
"AssociatedRuleApprovalType": null,
"AssociatedRulePartyType": "Targeted Group",
"AssociatedRulePartyName": "Operational Owner",
"AssociatedAdditionalComment": ""
},
{
"AssociatedCI": "xyza004( OPERATING SYSTEM )",
"AssociatedRuleName": "Default Impact ",
"AssociatedRuleApprovalType": null,
"AssociatedRulePartyType": "Targeted Group",
"AssociatedRulePartyName": "Technical Owner",
"AssociatedAdditionalComment": "Substitute Role"
}
],
"PossibleApprovers": [
{
"Approver": {
"Id": "Vzz436",
"Display": "some name",
"LineOfBusinessCode": "25",
"LineOfBusinessName": "Unix",
"LineOfBusinessHierarchy": null,
"PhoneNumber": "+123456789",
"RoleName": null,
"FullName": null,
"LineOfBusiness": null,
"ErrorMessage": null
},
"IsEscalation": false,
"IsDelegate": false
},
{
"Approver": {
"Id": "ppp71",
"Display": "more names",
"LineOfBusinessCode": "5",
"LineOfBusinessName": "Tech",
"LineOfBusinessHierarchy": null,
"PhoneNumber": "+987654321",
"RoleName": null,
"FullName": null,
"LineOfBusiness": null,
"ErrorMessage": null
},
"IsEscalation": false,
"IsDelegate": false
},
{
"Approver": {
"Id": "aaa5",
"Display": "mickey mouse",
"LineOfBusinessCode": "8",
"LineOfBusinessName": "Digital",
"LineOfBusinessHierarchy": null,
"PhoneNumber": "+87877676665",
"RoleName": null,
"FullName": null,
"LineOfBusiness": null,
"ErrorMessage": null
},
"IsEscalation": false,
"IsDelegate": false
}
],
"OriginalApprovals": [ ],
"AggregatedApproval": null,
"IsAggregated": false,
"AggregationId": 0,
"UpdatedBy": null,
"UpdatedDt": null,
"IsGroupActive": false
}
This is how you can get all ID's of the approvers, delimited by a semi-colon.
var data = {
"ApprovalSession": "3ebd4e73-7fc5-4113-9ccd-18833318ee09",
"LoadStatus": 0,
"Index": 0,
"ApprovalId": 0,
"Type": null,
"Approver": null,
"ApproverDisplay": null,
"Status": null,
"CreatedBy": null,
"CanBeRemoved": false,
"ConfigurationItems": [
"cigs01e4a002( OPERATING SYSTEM )",
"cigs01e4a002( OPERATING SYSTEM )",
"cigs01e4a004( OPERATING SYSTEM )",
"cigs01e4a004( OPERATING SYSTEM )"
],
"ApprovalReasons": [
{
"AssociatedCI": "abc4a002( OPERATING SYSTEM )",
"AssociatedRuleName": "Default Impact",
"AssociatedRuleApprovalType": null,
"AssociatedRulePartyType": "Targeted Group",
"AssociatedRulePartyName": "Operational Owner",
"AssociatedAdditionalComment": ""
},
{
"AssociatedCI": "xyza004( OPERATING SYSTEM )",
"AssociatedRuleName": "Default Impact ",
"AssociatedRuleApprovalType": null,
"AssociatedRulePartyType": "Targeted Group",
"AssociatedRulePartyName": "Technical Owner",
"AssociatedAdditionalComment": "Substitute Role"
}
],
"PossibleApprovers": [
{
"Approver": {
"Id": "Vzz436",
"Display": "some name",
"LineOfBusinessCode": "25",
"LineOfBusinessName": "Unix",
"LineOfBusinessHierarchy": null,
"PhoneNumber": "+123456789",
"RoleName": null,
"FullName": null,
"LineOfBusiness": null,
"ErrorMessage": null
},
"IsEscalation": false,
"IsDelegate": false
},
{
"Approver": {
"Id": "ppp71",
"Display": "more names",
"LineOfBusinessCode": "5",
"LineOfBusinessName": "Tech",
"LineOfBusinessHierarchy": null,
"PhoneNumber": "+987654321",
"RoleName": null,
"FullName": null,
"LineOfBusiness": null,
"ErrorMessage": null
},
"IsEscalation": false,
"IsDelegate": false
},
{
"Approver": {
"Id": "aaa5",
"Display": "mickey mouse",
"LineOfBusinessCode": "8",
"LineOfBusinessName": "Digital",
"LineOfBusinessHierarchy": null,
"PhoneNumber": "+87877676665",
"RoleName": null,
"FullName": null,
"LineOfBusiness": null,
"ErrorMessage": null
},
"IsEscalation": false,
"IsDelegate": false
}
],
"OriginalApprovals": [ ],
"AggregatedApproval": null,
"IsAggregated": false,
"AggregationId": 0,
"UpdatedBy": null,
"UpdatedDt": null,
"IsGroupActive": false
}
data.PossibleApprovers.forEach(function (approver) { document.write(approver.Approver.Id + ';')})

How to read jsonp response

I have a json file (http://example.com/usr/details?jsonp=parseRespond ) on a another server that gives the response
{
"id": "5572a7d648b33a462d79145d",
"avatarHash": null,
"bio": "",
"bioData": null,
"confirmed": false,
"fullName": "Ender Widgin",
"idPremOrgsAdmin": null,
"initials": "EW",
"memberType": "normal",
"products": [],
"status": "disconnected",
"url": "https://example.com/enderwidgin",
"username": "enderwidgin",
"avatarSource": null,
"email": null,
"gravatarHash": null,
"idBoards": [],
"idOrganizations": [],
"loginTypes": null,
"oneTimeMessagesDismissed": null,
"prefs": null,
"trophies": [],
"uploadedAvatarHash": null,
"premiumFeatures": [],
"idBoardsPinned": null,
"organizations": [],
"boards": [],
"actions": []
}
How can I write this response in a div
function parseRespond(){
// how to get the data ?
}
Thanks in advance!
JSON.parse may be helpful,
function parseRespond(response){
response = JSON.parse(response);
}

Object can not access in angularjs ng-model?

I want to display client id and country based on user selecting client from client list,I can be display entire selected object but can not display selected client details.
<label class="control-label red">Client</label>
{{selectedClient}}
<select class="form-control" ng-model="selectedClient">
<option ng-repeat="client in clients" value="{{client.id}}">{{client.name}}</option>
</select>
<a href="javascript:void(0)" data-toggle="modal" data-target="#addressModel"><i class="fa fa-map-marker"></i>
{{selectedClient.id}},{{selectedClient.address_info.country}}
</a>
Here selectedClient is displaying accordingly selecting from select-box,but selectedClient.id and selectedClient.address_info.country is not displaying even though they holding some values.
output of selectedClient is,
{
"id": 127,
"payment_terms_id": null,
"name": "Shihabs company",
"note": null,
"created_by": 0,
"updated_by": null,
"deleted_by": null,
"created_at": "2015-03-09 10:32:31",
"updated_at": "2015-03-09 10:32:31",
"deleted_at": null,
"status": 1,
"payment_term": null,
"address_info": {
"id": 54,
"client_id": 127,
"street": null,
"city": null,
"pobox": null,
"country": null,
"phone": null,
"work_phone": null,
"mobile": null,
"email": null,
"website": null,
"billing_street": null,
"billing_city": null,
"billing_pobox": null,
"billing_country": null,
"billing_phone": null,
"billing_work_phone": null,
"billing_mobile": null,
"billing_email": null,
"shipping_street": null,
"shipping_city": null,
"shipping_pobox": null,
"shipping_country": null,
"shipping_phone": null,
"shipping_work_phone": null,
"shipping_mobile": null,
"shipping_email": null,
"created_by": null,
"updated_by": null,
"deleted_by": null,
"created_at": "2015-03-09 10:32:31",
"updated_at": "2015-03-09 10:32:31",
"deleted_at": null,
"status": 1
}
}
try this way to bind select option
<select ng-model="selectedClient" ng-options="client.name for client in
clients"></select>

Categories

Resources