{"id":"9ada919e706d36a","definitionId":"57305c33e237893b","name":"Payload Transformer","createdAt":"2023-12-31T09:48:46.458817+00:00","version":2,"toolVersion":"3.0.0.0","variables":[{"id":"8a2e79235ed79941","name":"HttpInput1","typeName":"Object","isArray":false,"value":"","storageDriverTypeName":"Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"},{"id":"788e5e22734ca270","name":"TransformedValue1","typeName":"Object","isArray":false,"value":"","storageDriverTypeName":"Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"},{"id":"842847cf23014337","name":"HttpInputString","typeName":"String","isArray":false,"value":"","storageDriverTypeName":"Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"},{"id":"4af554559114a229","name":"QueryStrings","typeName":"ObjectDictionary","isArray":false,"storageDriverTypeName":"Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"},{"id":"e8968923e70aaa52","name":"Script","typeName":"String","isArray":false,"storageDriverTypeName":"Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"}],"inputs":[],"outputs":[],"outcomes":[],"customProperties":{"Elsa:WorkflowContextProviderTypes":[]},"isReadonly":false,"isLatest":true,"isPublished":true,"options":{"autoUpdateConsumingWorkflows":false},"root":{"type":"Elsa.Flowchart","version":1,"id":"5c7ae86ea915f966","nodeId":"Workflow1:5c7ae86ea915f966","metadata":{},"customProperties":{"source":"FlowchartJsonConverter.cs:45","notFoundConnections":[],"canStartWorkflow":false,"runAsynchronously":false},"activities":[{"path":{"typeName":"String","expression":{"type":"Literal","value":"test"}},"supportedMethods":{"typeName":"String[]","expression":{"type":"Object","value":"[\u0022POST\u0022]"}},"authorize":{"typeName":"Boolean","expression":{"type":"Literal","value":"False"}},"policy":{"typeName":"String","expression":{"type":"Literal","value":""}},"requestTimeout":null,"requestSizeLimit":null,"fileSizeLimit":null,"allowedFileExtensions":null,"blockedFileExtensions":null,"allowedMimeTypes":null,"exposeRequestTooLargeOutcome":false,"exposeFileTooLargeOutcome":false,"exposeInvalidFileExtensionOutcome":false,"exposeInvalidFileMimeTypeOutcome":false,"parsedContent":{"typeName":"Object","memoryReference":{"id":"842847cf23014337"}},"files":null,"routeData":null,"queryStringData":{"typeName":"ObjectDictionary","memoryReference":{"id":"4af554559114a229"}},"headers":null,"result":null,"id":"2f593b78e0f4790e","nodeId":"Workflow1:5c7ae86ea915f966:2f593b78e0f4790e","name":"HttpEndpoint1","type":"Elsa.HttpEndpoint","version":1,"customProperties":{"canStartWorkflow":true,"runAsynchronously":false},"metadata":{"designer":{"position":{"x":-60,"y":-195},"size":{"width":180,"height":80}}}},{"variable":{"id":"e8968923e70aaa52","name":"Script","typeName":"String","storageDriverTypeName":"Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"},"value":{"typeName":"Object","expression":{"type":"JavaScript","value":"getQueryStrings().script"}},"id":"a238426e74e64571","nodeId":"Workflow1:5c7ae86ea915f966:a238426e74e64571","name":"SetVariable2","type":"Elsa.SetVariable","version":1,"customProperties":{"canStartWorkflow":false,"runAsynchronously":false},"metadata":{"designer":{"position":{"x":240,"y":-180},"size":{"width":264.703125,"height":50}},"displayText":"Set Script from QueryString"}},{"cases":[{"label":"Python","condition":{"type":"JavaScript","value":"getScript() == \u0022python\u0022"}},{"label":"C#","condition":{"type":"JavaScript","value":"getScript() == \u0022csharp\u0022"}},{"label":"JavaScript","condition":{"type":"JavaScript","value":"getScript() == \u0022javascript\u0022"}}],"mode":{"typeName":"Elsa.Workflows.SwitchMode, Elsa.Workflows.Core","expression":{"type":"Literal","value":"MatchFirst"}},"id":"6eb54f0c726db174","nodeId":"Workflow1:5c7ae86ea915f966:6eb54f0c726db174","name":"FlowSwitch1","type":"Elsa.FlowSwitch","version":1,"customProperties":{"canStartWorkflow":false,"runAsynchronously":false},"metadata":{"designer":{"position":{"x":644.6875,"y":-235},"size":{"width":160,"height":160}}}},{"script":{"typeName":"String","expression":{"type":"Literal","value":"public class JsonTransformer\n{\n public string RestructureJson(string httpInput)\n {\n // Check if \u0027data\u0027 and \u0027array\u0027 keys exist\n if (JsonNode.Parse(httpInput) is JsonObject data \u0026\u0026 data[\u0022data\u0022] is JsonObject dataObj \u0026\u0026 dataObj[\u0022array\u0022] is JsonArray arrayItems)\n {\n // Restructure the array into individual objects\n for (var i = 0; i \u003C arrayItems.Count; i\u002B\u002B)\n {\n var objectKey = $\u0022object{i \u002B 1}\u0022;\n dataObj[objectKey] = arrayItems[i]!.ToString();\n }\n\n // Remove the original array from the data\n dataObj.Remove(\u0022array\u0022);\n }\n else\n {\n throw new ArgumentException(\u0022JSON structure is not as expected.\u0022);\n }\n\n // Return the modified JSON as a string\n return JsonSerializer.Serialize(data, new JsonSerializerOptions { WriteIndented = true });\n }\n}\n\nvar httpInput1 = Variables.Get\u003Cstring\u003E(\u0022HttpInputString\u0022);\nvar result = new JsonTransformer().RestructureJson(httpInput1);\nVariables.Set(\u0022TransformedValue1\u0022, result);"}},"possibleOutcomes":null,"result":null,"id":"5793277d0c0af5df","nodeId":"Workflow1:5c7ae86ea915f966:5793277d0c0af5df","name":"RunCSharp1","type":"Elsa.RunCSharp","version":1,"customProperties":{"canStartWorkflow":false,"runAsynchronously":false},"metadata":{"designer":{"position":{"x":999.04296875,"y":-165},"size":{"width":83.640625,"height":50}}}},{"script":{"typeName":"String","expression":{"type":"Literal","value":"import json\n\ndef restructure_json(http_input):\n # Parse the JSON input\n data = json.loads(http_input)\n\n # Check if \u0027data\u0027 and \u0027array\u0027 keys exist\n if \u0027data\u0027 in data and \u0027array\u0027 in data[\u0027data\u0027]:\n array_items = data[\u0027data\u0027][\u0027array\u0027]\n \n # Restructure the array into individual objects\n for i, item in enumerate(array_items):\n object_key = f\u0027object{i\u002B1}\u0027\n data[\u0027data\u0027][object_key] = item\n \n # Remove the original array from the data\n del data[\u0027data\u0027][\u0027array\u0027]\n else:\n raise ValueError(\u0022JSON structure is not as expected.\u0022)\n\n # Return the modified JSON as a string\n return json.dumps(data, indent=4)\n\n# Example usage\nHttpInput1 = variables.get(\u0027HttpInputString\u0027)\nresult = restructure_json(HttpInput1)\nvariables.set(\u0027TransformedValue1\u0027,result)\n"}},"possibleOutcomes":{"typeName":"String[]","expression":{"type":"Object","value":"[]"}},"result":null,"id":"2eb2c8d2e1474d63","nodeId":"Workflow1:5c7ae86ea915f966:2eb2c8d2e1474d63","name":"RunPython1","type":"Elsa.RunPython","version":1,"customProperties":{"canStartWorkflow":false,"runAsynchronously":false},"metadata":{"designer":{"position":{"x":999.04296875,"y":-285},"size":{"width":113.75,"height":50}}}},{"statusCode":{"typeName":"System.Net.HttpStatusCode, System.Net.Primitives","expression":{"type":"Literal","value":"InternalServerError"}},"content":{"typeName":"Object","expression":{"type":"Literal","value":"Sorry :( javascript is not implemented."}},"contentType":null,"responseHeaders":{"typeName":"Elsa.Http.Models.HttpHeaders, Elsa.Http","expression":{"type":"Literal","value":{}}},"id":"78c00fd13d098514","nodeId":"Workflow1:5c7ae86ea915f966:78c00fd13d098514","name":"WriteHttpResponse3","type":"Elsa.WriteHttpResponse","version":1,"customProperties":{"canStartWorkflow":false,"runAsynchronously":false},"metadata":{"designer":{"position":{"x":999.04296875,"y":-60},"size":{"width":227.046875,"height":81.90625}},"description":"JavaScript not implemented","showDescription":true}},{"mode":{"typeName":"Elsa.Workflows.Activities.Flowchart.Models.FlowJoinMode, Elsa.Workflows.Core","expression":{"type":"Literal","value":"WaitAny"}},"id":"2e863fe1c990e1b2","nodeId":"Workflow1:5c7ae86ea915f966:2e863fe1c990e1b2","name":"FlowJoin1","type":"Elsa.FlowJoin","version":1,"customProperties":{"canStartWorkflow":false,"runAsynchronously":false},"metadata":{"designer":{"position":{"x":1287.3203125,"y":-235},"size":{"width":98.265625,"height":50}}}},{"statusCode":{"typeName":"System.Net.HttpStatusCode, System.Net.Primitives","expression":{"type":"Literal","value":"BadRequest"}},"content":{"typeName":"Object","expression":{"type":"Literal","value":"Please provide a valid script type in the url parameters. Example: \u0022?script=csharp\u0022. Valid types: javascript, csharp, python"}},"contentType":null,"responseHeaders":{"typeName":"Elsa.Http.Models.HttpHeaders, Elsa.Http","expression":{"type":"Literal","value":{}}},"id":"72ef464845828396","nodeId":"Workflow1:5c7ae86ea915f966:72ef464845828396","name":"WriteHttpResponse2","type":"Elsa.WriteHttpResponse","version":1,"customProperties":{"canStartWorkflow":false,"runAsynchronously":false},"metadata":{"designer":{"position":{"x":999.04296875,"y":100},"size":{"width":183.640625,"height":81.90625}},"showDescription":true,"description":"Bad request"}},{"statusCode":{"typeName":"System.Net.HttpStatusCode, System.Net.Primitives","expression":{"type":"Literal","value":"OK"}},"content":{"typeName":"Object","expression":{"type":"Python","value":"variables.get(\u0027TransformedValue1\u0027) "}},"contentType":{"typeName":"String","expression":{"type":"Literal","value":"text/json"}},"responseHeaders":{"typeName":"Elsa.Http.Models.HttpHeaders, Elsa.Http","expression":{"type":"Literal","value":{}}},"id":"ed4d560b2d422c19","nodeId":"Workflow1:5c7ae86ea915f966:ed4d560b2d422c19","name":"WriteHttpResponse1","type":"Elsa.WriteHttpResponse","version":1,"customProperties":{"canStartWorkflow":false,"runAsynchronously":false},"metadata":{"designer":{"position":{"x":1520,"y":-246.90625},"size":{"width":252.84375,"height":81.90625}},"description":"Echo back the transformed input","showDescription":true}}],"connections":[{"source":{"activity":"6eb54f0c726db174","port":"Default"},"target":{"activity":"72ef464845828396","port":"In"}},{"source":{"activity":"6eb54f0c726db174","port":"JavaScript"},"target":{"activity":"78c00fd13d098514","port":"In"}},{"source":{"activity":"2eb2c8d2e1474d63","port":"Done"},"target":{"activity":"2e863fe1c990e1b2","port":"In"}},{"source":{"activity":"5793277d0c0af5df","port":"Done"},"target":{"activity":"2e863fe1c990e1b2","port":"In"}},{"source":{"activity":"2e863fe1c990e1b2","port":"Done"},"target":{"activity":"ed4d560b2d422c19","port":"In"}},{"source":{"activity":"6eb54f0c726db174","port":"C#"},"target":{"activity":"5793277d0c0af5df","port":"In"}},{"source":{"activity":"2f593b78e0f4790e","port":"Done"},"target":{"activity":"a238426e74e64571","port":"In"}},{"source":{"activity":"a238426e74e64571","port":"Done"},"target":{"activity":"6eb54f0c726db174","port":"In"}},{"source":{"activity":"6eb54f0c726db174","port":"Python"},"target":{"activity":"2eb2c8d2e1474d63","port":"In"}}]}}