I'm getting an error displayed in the output of an Azure Logic App step, for an Action type of 'Transform_JSON_to_JSON' (a Liquid transform that I'm using to transform some JSON). I'm not seeing what's causing the error?
The input to the liquid action is as follows. This formats as valid JSON
[{"DeviceType":"Scanner","Code":"ABC","CustomerId":null,"FirstName":"John","LastName":"Doe","TransactionType":"Actionable","TransactionSubTypes":["ScanFailed"],"Message":"Scan failed.","Data":null,"Status":"Pending","Text":null,"AgentId":null,"AgentName":null,"NodeId":"12345","Timestamp":"2021-10-26T22:43:37.695759+00:00","UTCTimeStamp":"2021-10-26T22:43:37.695763Z"}]
The liquid template is:
[
{% for transaction in content %}
{
"DeviceType": "{{content.DeviceType}}",
"Code": "{{content.Code}}"
}
{% endfor %}
]
The raw output from the liquid action in the Azure Logic App designer is
"{\"StatusCode\":400,\"ErrorCode\":18,\"Details\":null,\"Message\":\"An error occurred while converting the transformed value to JSON. The transformed value is not a valid JSON. 'After parsing a value an unexpected character was encountered: {. Path '[0]', line 8, position 6.'\",\"Data\":{},\"InnerException\":{\"ClassName\":\"Newtonsoft.Json.JsonReaderException\",\"Message\":\"After parsing a value an unexpected character was encountered: {. Path '[0]', line 8, position 6.\",\"Data\":null,\"InnerException\":null,\"HelpURL\":null,\"StackTraceString\":\" at Newtonsoft.Json.JsonTextReader.ParsePostValue(Boolean ignoreComments)\\r\\n at Newtonsoft.Json.JsonTextReader.Read()\\r\\n at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)\\r\\n at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)\\r\\n at Newtonsoft.Json.Linq.JArray.Load(JsonReader reader, JsonLoadSettings settings)\\r\\n at Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)\\r\\n at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)\\r\\n at Microsoft.Azure.Function.Common.BaseLiquidTransformer.ParseTransformedContent(String transformedContent, JSchema schema) in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.Common\\\\Liquid\\\\BaseLiquidTransformer.cs:line 127\",\"RemoteStackTraceString\":null,\"RemoteStackIndex\":0,\"ExceptionMethod\":\"8\\nParsePostValue\\nNewtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed\\nNewtonsoft.Json.JsonTextReader\\nBoolean ParsePostValue(Boolean)\",\"HResult\":-2146233088,\"Source\":\"Newtonsoft.Json\",\"WatsonBuckets\":null},\"TargetSite\":{\"Name\":\"ParseTransformedContent\",\"AssemblyName\":\"Microsoft.Azure.Function.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\",\"ClassName\":\"Microsoft.Azure.Function.Common.BaseLiquidTransformer\",\"Signature\":\"Newtonsoft.Json.Linq.JToken ParseTransformedContent(System.String, Newtonsoft.Json.Schema.JSchema)\",\"Signature2\":\"Newtonsoft.Json.Linq.JToken ParseTransformedContent(System.String, Newtonsoft.Json.Schema.JSchema)\",\"MemberType\":8,\"GenericArguments\":null},\"StackTrace\":\" at Microsoft.Azure.Function.Common.BaseLiquidTransformer.ParseTransformedContent(String transformedContent, JSchema schema) in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.Common\\\\Liquid\\\\BaseLiquidTransformer.cs:line 133\\r\\n at Microsoft.Azure.Function.LiquidTransform.LiquidTransformRequestProcessor.GetTransformedContentResponseMessage(HttpRequestMessage request, LiquidTransformKind transformKind, String transformedContent, JSchema outputSchema) in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.LiquidTransform\\\\LiquidTransformRequestProcessor.cs:line 91\\r\\n at Microsoft.Azure.Function.LiquidTransform.LiquidTransformRequestProcessor.<ProcessRequest>d__2.MoveNext() in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.LiquidTransform\\\\LiquidTransformRequestProcessor.cs:line 60\",\"HelpLink\":null,\"Source\":\"Microsoft.Azure.Function.Common\",\"HResult\":-2146233088}"
I had a missing comma to separate each JSON object literal within the output array (and also was referencing the incorrect variable to get properties for each item, in the loop). The correct liquid template is: