Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

vimagination.zapto.org/json2xml

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimagination.zapto.org/json2xml

Go Modules
Version
v1.0.1
Version published
Created
Source

json2xml

CI Go Reference Go Report Card

-- import "vimagination.zapto.org/json2xml"

Package json2xml converts a JSON structure to XML.

Highlights

  • Safely converts JSON to XML with type-based tags.
  • Object key names are stored as a name attribute.

Usage

package main

import (
	"encoding/json"
	"encoding/xml"
	"fmt"
	"strings"

	"vimagination.zapto.org/json2xml"
)

func main() {
	var buf strings.Builder

	jsonData := `` +
		`[
	{
		"A": [
			{
				"B": 3.14159,
				"C": null
			},
			"D",
			"E",
			null,
			1.234
		],
		"F": 123
	},
	"G"
]`

	x := xml.NewEncoder(&buf)

	x.Indent("", "\t")

	if err := json2xml.Convert(json.NewDecoder(strings.NewReader(jsonData)), x); err != nil {
		fmt.Printf("unexpected error: %s\n", err)

		return
	}

	x.Flush()

	fmt.Println(buf.String())

	// Output:
	// <array>
	//	<object>
	//		<array name="A">
	//			<object>
	//				<number name="B">3.14159</number>
	//				<null name="C"></null>
	//			</object>
	//			<string>D</string>
	//			<string>E</string>
	//			<null></null>
	//			<number>1.234</number>
	//		</array>
	//		<number name="F">123</number>
	//	</object>
	//	<string>G</string>
	// </array>
}

Documentation

Full API docs can be found at:

https://pkg.go.dev/vimagination.zapto.org/json2xml

FAQs

Package last updated on 30 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts