JSON to XML

Convert a JSON object into an XML string

Script helper

by jaller94 ยท 9/5/2022

  • Submitted by jaller94 Deno
    Created 1358 days ago
    1
    import { toXML } from "https://esm.sh/[email protected]?target=deno";
    2
    
    
    3
    // For example JSON objects, have a look at https://github.com/davidcalhoun/jstoxml
    4
    export async function main(json: object | string, indent?: string, header?: boolean | string, selfCloseTags: boolean) {
    5
        if (typeof json === 'string') {
    6
            json = JSON.parse(json);
    7
        }
    8
    	return toXML(json, {
    9
            indent,
    10
            header,
    11
            selfCloseTags,
    12
        });
    13
    }