format flare.jason from existing json - d3.js

I am formatting regular json data to a flare format for a chart I am working on and ran into an issue creating the children. I have a fiddle of my current work and was hoping someone could spot what I missed.
not working
I only get it to return this [no children]:
[
{
"parent": "new skill",
"name": "Advanced",
"AgtName": "amy"
},
{
"parent": "new skill",
"name": "Advanced",
"AgtName": "GARY"
}
]

Since you are using d3, you can use d3.nest to get a hierarchical structure from an array. Here is a snippet based on your code:
let tree = d3.nest().key(node => node.name).entries(data);
Working demo

Related

Filtering JSON based on sub array in a Power Automate Flow

I have some json data that I would like to filter in a Power Automate Flow.
A simplified version of the json is as follows:
[
{
"ItemId": "1",
"Blah": "test1",
"CustomFieldArray": [
{
"Name": "Code",
"Value": "A"
},
{
"Name": "Category",
"Value": "Test"
}
]
},
{
"ItemId": "2",
"Blah": "test2",
"CustomFieldArray": [
{
"Name": "Code",
"Value": "B"
},
{
"Name": "Category",
"Value": "Test"
}
]
}
]
For example, I wish to filter items based on Name = "Code" and Value = "A". I should be left with the item with ItemId 1 in that case.
I can't figure out how to do this in Power Automate. It would be nice to change the data structure, but this is the way the data is, and I'm trying to work out if this is possible in Power Automate without changing the data itself.
Firstly, I had to fix your JSON, it wasn't complete.
Secondly, filtering on sub array information isn't what I'd call easy. However, to get around the limitations, you can perform a bit of trickery.
Prior to the step above, I create a variable of type Array and called it Array.
In the step above, the left hand side expression is ...
string(item()?['CustomFieldArray'])
... and the contains comparison on the right hand side is simply as you can see, a string with the appropriate filter value ...
{"Name":"Code","Value":"A"}
... it's not an expression or a proper object, just a string.
If you need to enhance it to cater for case sensitive values, just set everything to lower case using the toLower expression on the left.
Although it's hard to see, that will produce your desired result ...
... you can see by the vertical scrollbars that it's reduced the size of the array.

MailChimp Campaign Update

i am trying to use campaigns/update in MailChimp.
However i still cannot understand how can i use it.
Can anyone please explain to me, for example how can i change the "from_email" parameter?
my current json for that purpose looks like this:
{
"apikey": "my_api_key",
"cid": "my_campaign_id",
"name": "options",
"value": ["list_id_value","subject_value","from_email_value"]
}
However when i send this json to campaigns/update, it returns error saying that "Can not update unknown option "2"".
How can i change the json so that i can update the "from_email"?
The API docs seem to be wrong. Try replacing [ ] with { } and giving field:pair values inside it. So, example to change the subject:
{
"apikey": "my_api_key",
"cid": "my_campaign_id",
"name": "options",
"value": {"subject": "My new subject"}
}

Mandrill API with Handlebars "each-loop" not working

Met problem when using Mandrill API to send transactional newsletters. I chose Handlebars for the template parameters. The user name was shown correctly, but data in the list (post titles) were empty. Please help indicate if anything I did wrong. Thank you!
The template is as below, sent to the endpoint /messages/send.json :
func genHTMLTemplate() string {
return "code generated template<br>" +
"Hi {{name}}, <br>" +
"{{#each posts}}<div>" +
"TITLE {{title}}, THIS {{this}}<br>" +
"</div>{{/each}}"
}
The API log in my Settings panel in mandrillapp.com shows the parameters:
{
"key": "xxxxxxxxxx",
"message": {
:
"merge_language": "handlebars",
"global_merge_vars": null,
"merge_vars": [
{
"rcpt": "xxxxxx#gmail.com",
"vars": [
{
"name": "posts",
"content": [
{
"title": "title A"
},
{
"title": "title B"
},
]
},
{
"name": "name",
"content": "John Doe"
}
]
}
],
:
},
:
}
And below is the email received. "title A" and "title B" are expected after "TITLE".
code generated template
Hi John Doe,
TITLE, THIS Array
TITLE, THIS Array
Mandrill decided to create custom handlebars helpers with some horrible, HORRIBLE names:
https://mandrill.zendesk.com/hc/en-us/articles/205582537-Using-Handlebars-for-Dynamic-Content#inline-helpers-available-in-mandrill
title and url will definitely give you grief if your objects happen to have keys named title and urlas well. Why they didn't name their helpers something like toTitleCase and encodeUrl is beyond me.
As far as arrays and #each is concerned, you can work around it by using {{this.title}} instead of {{title}}.
After testing with Mandrill's sample code here I found the key "title" just doesn't work. Dunno the reason (a reserved keyword of Mandrill?) but replace it with "title1", "titleX" or something else it can be rendered correctly.
{
"name": "posts",
"content": [
{
"title": "blah blah" // "title1" or something else works
},
}
while using handlebars as the merge language 'title' is the reserved helpername which is used in handlebars which makes your text in title case. If you do only {{title}} by default it considers as title the empty text. try giving it {{title title}} which should work or changing the key name to something else ( if you dont want your title in title case )
I know this is late but it could be of use to someone trying to debug this issue currently. Take note of this point in the Mandrill documentation
There are two main ways to add dynamic content via merge tags: Handlebars or the Mailchimp merge language. You may already be familiar with the Mailchimp merge language from creating and editing Mailchimp templates. We also offer a custom implementation of Handlebars, which is open source and offers greater flexibility.
To set your merge language, navigate to Sending Defaults and select Mailchimp or Handlebars from the Merge Language drop-down menu.
I've run into a similar issue on Sending Blue, where their default configuration does not enable handle bars so it won't evaluate them.

D3 treemap json data format

I'm new to d3js. I've gone through several examples of the treemap visualization and noticed that the data has the same hierarchical structure:
{
"name": "flare",
"children": [
...
]
...
}
But what if I have an array of objects with same set of properties without nesting:
[
{
"CourseID": "15.010B",
"Subject": "15.01",
"Section": "B",
"Department": "Managerial Economics",
"Professor": "Doyle",
...
},
{
"CourseID": "15.010B",
"Subject": "15.01",
"Section": "B",
...
},
...
]
Should I make it hierarchical by myself? Can you provide me with visual treemap example for this type of data format. Thanks in advance.
d3's built-in nest feature can easily create this type of hierarchical data for you, for example:
var nest = d3.nest()
.key(function(d) { return d.Department; })
.key(function(d) { return d.Subject; })
.key(function(d) { return d.Section; })
.entries(_dataset_name_);
will create a suitably hierarchical dataset.
Formatting your JSON into a hierarchical structure can be tedious. I used Google Refine which allowed me to import CSV,JSON or Excel files and "refine" them into the JSON structures of my choice. It seem a bit of a pain to set up, but once completed, you will have a tool for manipulating your data into structures of your choice going forward.

datatables server side response nesting

Simple issue regarding usage of datatables (http://www.datatables.net) and server side data retrieval.
Datatables expects a special format from the server, to be in the root of the response:
{
"sEcho": 1,
"iTotalRecords": "57",
"iTotalDisplayRecords": "57",
"aaData": [
{
"engine": "Gecko",
"browser": "Firefox 1.0",
"platform": "Win 98+ / OSX.2+",
"version": "1.7",
"grade": "A"
},...
]
}
But I want to nest all of this in another place in my json response from the server:
{
myshit: "",
status: "success",
morestuff: "yoyo",
datatables: { here will be all of the json related to datatables }
}
I haven't found a property for this in the API.
The only options I know about, right now, is to define all the columns with the exact nested property they should look for.
Do you know of such a property? or can suggest a good way to achieve this nesting?
Because sAjaxSource expects the dataset in the particular order, you would have to use $.getJSON instead to have the nested layout you described

Resources