html2json

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 3 Imported by: 0

README

go-html2json

Go package to convert an HTML string to JSON.

Usage

package main

import (
  "fmt"
  "github.com/bradpurchase/go-html2json"
)

func main() {
  html := "<div><p>Hello World</p></div>"
  json, err := html2json.Convert(html)
  if err != nil {
    panic(err)
  }
  fmt.Println(json) // {"tag":"html","attrs":{},"children":[{"tag":"head","attrs":{},"children":null},{"tag":"body","attrs":{},"children":[{"tag":"div","attrs":{},"children":[{"tag":"p","attrs":{},"children":[{"tag":"text","attrs":{"text":"Hello World"},"children":[{"tag":"","attrs":null,"children":null}]}]}]}]}]}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(htmlString string) (string, error)

Types

type HTMLElement

type HTMLElement struct {
	Tag      string            `json:"tag"`
	Attrs    map[string]string `json:"attrs"`
	Children []*HTMLElement    `json:"children"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL