Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

JSON Structure Build

mclane20
6 - Meteoroid

Hi All, 

 

I have reviewed some of the documents and articles on using the Json tool. I cant seem to get it work exactly how I need it. Please let me know if you can help. Below is the sample Data set and then also the json structure it needs to become. 

 

Data Set:

 

hostsourceindexsourcetypeevent-typeevent-processevent-actionevent-pod
AlteryxBPBP1BP2StuckProcess ARestart ProcessTeam A
AlteryxBPBP1BP2TerminatedProcess BRestart VDITeam B
AlteryxBPBP1BP2QueueProcess CAdd moreTeam C

 

host, index, source, and source type will be the same value only things that change are the events. This payload will be generated and sent via an api call to a logging system. 

 

Desired Json Output: 

{
    "host": "Alteryx",
    "source": "BP",
"index": "BP1",
"sourcetype": "BP2", "event":
[
{
"type": "Stuck", "process": "Process A", "action": "Restart Process",
"pod": "Team A" },
{
"type": "Terminated",
"process": "Process B",
"action": "Restart VDI",
"pod": "Team B"
},
{
"type": "Queue",
"process": "Process C",
"action": "Add more",
"pod": "Team C"
}
] }

 Thanks so much for your help and feedback. 

6 REPLIES 6
grossal
15 - Aurora
15 - Aurora

Hi @mclane20,

 

your desired Output looks very odd to me. I'd understand if you want the "general information" in a higher hierarchy than the rest, but only having the top level information in the first element seems strange to me.

 

Alex

mclane20
6 - Meteoroid

Hi I updated the Json payload I was missing some brackets, apologies. My intent for this structure is to be able to send multiple events in one payload. the basic info one needs to be there once while the event data could have many records. 

grossal
15 - Aurora
15 - Aurora

I am not aware of an Alteryx way to do this. I have tested the JSON build, JSON build v2 and JSON Create from the CReW Macros, but none of them worked.

 

However, we still have the Python tool to do the magic.

grossal_0-1587764124532.png

 

Output:

grossal_1-1587764149352.png

 

Beautified:

grossal_2-1587764166483.png

 

You can remove the outer [] if you want (you didn't have them in your Desired Output.

 

What happens inside the Python tool is quiet simple:

grossal_3-1587764285150.png

 

Workflow attached. Let me know what you think.

 

Best

Alex

danilang
19 - Altair
19 - Altair

Hi @mclane20 

 

Here's a way you can accomplish the same thing without resorting to python, using the CReWs JSON Create macro

 

w.png

This workflow separates the inner event columns and parses them into a single JSON sting and appends this to the outer level.  This is passed again through  JSON Create to create an object with a nested array.  After some clean-up to remove the escaped characters, you get 

 

 

 

{
	"host":"Alteryx",
	"source":"BP",
	"index":"BP1",
	"sourcetype":"BP2",
	"Event":
	[
	{
		"event-type":"Stuck",
		"event-process":"Process A",
		"event-action":"Restart Process",
		"event-pod":"Team A"
	},
	{
		"event-type":"Terminated",
		"event-process":"Process B",
		"event-action":"Restart VDI",
		"event-pod":"Team B"
	},
	{
		"event-type":"Queue",
		"event-process":"Process C",
		"event-action":"Add more",
		"event-pod":"Team C"
	}
	]
}

 

Note: The output is a actually single string with no line breaks.  I added those manually. 

 

Dan

 

 

Alc2020
7 - Meteor

Hi @danilang,

 

I need the same workflow as you did.  I downloaded yours but I'm getting an error on the parsing tool (please see attached).  How do I fix that?  Thanks in advance.

 

Capture.PNG

daw44
6 - Meteoroid

You need to install the popular CREW macros. They are available at http://www.chaosreignswithin.com/p/macros.html.

Labels