A "Copy Everything" liquid template for JSON to JSON

432 Views Asked by At

Back in the xsl(t) days.... if you did an "xml to xml" transformation, you could do a "copy *star dot *star" (copy everything "as is").. thing with an xsl template (probably) like the below.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Is there any kind of liquid short-syntax that would do this for a JSON to JSON transformation?

I have internet-searched ... but the search phrases are very ambiguous.

Things I found (but are incomplete a far as answers as far as I can tell).

https://social.msdn.microsoft.com/Forums/en-US/1c6ae215-9dad-4921-b7ef-a826443a47bb/liquid-json-to-json-template-with-unknown-property-names?forum=azurelogicapps

2

There are 2 best solutions below

0
On

Just passing the entire object shoule work, like {{content}}. There's a working example in this SO answer.

0
On

Yes, there are liquid short-syntax options available for a JSON to JSON transformation. For example, the following template will perform a copy of everything "as is" in JSON using the liquid short-syntax:

Code snippet in Python for reference....

{% assign input = your_input_json | 
jsonify %}
{{ input | pretty_json }}

Here, your_input_json is the input JSON data that needs to be transformed, and the jsonify filter is used to ensure that the input is properly formatted as JSON. The pretty_json filter is used to output the transformed JSON data in a nicely formatted way. Note that this syntax assumes that you are using the Liquid templating language.