How do you pass parameters to Azure Logic Apps Liquid Connector for JSON-JSON transformation? - json

I have a Liquid transformation step in my Azure Logic App, using the "Transform JSON to JSON" version of the Liquid connector. I need to pass some parameters into the transformation - these values will end up in the JSON output from the transformation.
Unfortunately, I can't find any documentation or examples on how you would pass such parameters into the Liquid map.

There's no way to specifically 'pass parameters' to a Liquid template because Liquid does not support that construct.
However, you can easily inject a Parameters object into the source JSON using the Compose Action. Then you access them like any other value.

Related

How can i test the dynamic json expression in my Logic app

I'm setting up a complex json expression to build up a request for an api. I would like to verify this expression somehow in a unittest.
Is there a library available that i can feed a json and the expression and it executes the expression so i can verify the result.
My expression contains various 'if', 'concat', 'json' statements.
Thanks
I am not aware of any external library, but any expression can be easily tested in a Logic App by creating a Compose action, using your expression in its Inputs box, running the Logic App and checking the Outputs.

How to pass input parameters to Liquid (Json) mapping ,this map will be used in Azure LogicApp

Generally in XSLT mapping we can pass input parameter like (eg; <xsl:param name="input:templateID "/>),
Similarly is there any way that we can pass parameters for? .Liquid (Json) mapping?
Please let me know if there is any such...
You can try adding/including the required parameter value into the source JSON using the Compose Action and then you can access that along with other parameters.
Here are couple of reference of liquid template for JSON transform:
https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-enterprise-integration-liquid-transform
https://rokhri.com/logic-app-using-liquid-template-to-transform-json/

How do I Pass JSON as a parameter to AWS Lambda

I have a CloudFormation template that consists of a Lambda function that reads messages from the SQS Queue.
Lambda function will read the message from the queue and transform it using a JSON template(Which I want it to be injected externally)
I will deploy different stacks for different products and for each product I will provide different JSON templates to be used for transformation.
I have different options but couldn't decide which one is better;
I can write all JSON files under the project and pack them together and pass related JSON name as a parameter to lambda.
I can store JSON files on S3 and pass S3 URL to lambda so I can read on runtime.
I can store JSON files on Dynamo DB and read from there using the same approach with 2
The first one seems like a better approach as I don't need to read from an external file on every lambda execution. But I will need to pack all templates together.
The last two are a more clear approach but require an external call to read JSON for every call.
Another approach could be (I'm not sure if it is possible) to inject a JSON file to Lambda on deploy from S3 bucket or sth. And Lambda function will read it like an environment variable.
As you can see from the cloudformation documentation Lambda environment variables can be only a Map of Strings, so the actual value you can pass to the function as an environment variable must be a String. You could pass your JSON as a string but the problem is that the max size for all environment variables is 4 KB.
If your templates are bigger and you don't want to call S3 or DynamoDB at runtime you could do a workaround like writing a simple shell script that copies the correct template file to the lambda folder before building and deploying the stack. This way the lambda gets deployed in a package with the code and only the desired json template.
I decided to go with S3 setup and also improved efficiency by storing Json on a global variable (after reading the first time). So I read once and use it for the lifetime of the Lambda container.
I'm not sure this is the best solution but works well enough for my scenario.

Django rest swagger and json definition

I'm pretty new to Django and I'm currently working on a project where Django-rest-framework is used and the documentation is created with Swagger trough the django-rest-swagger package.
I'm trying to find (or generate) a swagger.json definition file, any idea on where it can be found with this package? I would like to use it to generate client side code.
Thanks
The swagger schema definition can be generated with https://github.com/signalfx/fetch-swagger-schema regardless the api implementation.
You can append ?format=openapi to the end of your docs URL and it will return the raw JSON text instead of the UI.
see here

HTML::Template Perl

IIs there a package similar to HTml::Template in perl which takes a JSON object and maps it to a HTML template file? I am building a web application using HTML::Template and will be receiving JSOn from a web services API, things will be made simple if I can templatize this JSOn to HTML instead of doing it the exact way HTML::Template requires.
HTML::Template just takes a data structure consisting of strings, hashes and arrays. JSON maps directly onto that.
$template->param(myData => JSON::Any->new->decode($json_string));
HTML::Template is a rather 'simple' templating engine - I am using quotes because its simplicity let's you do whatever you need in a view part from the Model View Controller architecture.
However, you can not execute arbitrary perl code inside a HTML::Template.
Also, due to the fact that in JSON you could have very complex data structures, I doubt that there are any suitable ways of using JSON in a straight way in your templates.
The only solution I see as possible is for you to use a Perl script that will parse the JSON, create some 'objects' and pass them to your templates. You already have that perl script - is the one that instantiate your HTML::Template object.
ok, a bit late, but:
HTML::Template always wants a hash of arrays of hashes and so on.
and you cannot navigate through the parameter stash.
If you want to do this, you might try out HTML::Template::Compiled which allows you to do this.
<tmpl_var some_hash.key.another_key[23] >
or with alternative delimiters:
[%= some_hash.key.another_key[23] %]
but note the documented differences of the module to HTML::Template.
So you decode your JSON string to a data structure and pass it to the template and then you can access all values somewhere deep in the structure.