jsoncr

package module
v0.0.0-...-6b9b84a Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 4 Imported by: 0

README

JSONCR

PkgGoDev

JSONCR is a Go package that provides method to remove comments and indentations in JSON. Both block and line comments are supported. Common use is to process the JSON config file.

Getting Started

Installing

$ go get github.com/thedevop/jsoncr

Example

    const j = `/* Comment */
{
    "example": "value" // more comment
}`
	condense, err := jsoncr.Remove(strings.NewReader(j))
	if err != nil {
        // error handling
    }
    var z interface{}
	err = json.Unmarshal(condense, &z)
	if err != nil {
        // error handling
	}

Documentation

Overview

Package jsoncr provides method to remove comments and indentations in JSON.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Remove

func Remove(r io.Reader) ([]byte, error)

Remove comments and indentations from r.

Example
package main

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

	"github.com/thedevop/jsoncr"
)

func main() {
	const j = `// JSON with commments
{	"configDesc": "configuration data", // config comment
	/* configBool:
		 false (default)
	*/
	"configBool": true					// override default
}`
	condenseJ, err := jsoncr.Remove(strings.NewReader(j))
	if err != nil {
		fmt.Println(err)
		return
	}
	var z interface{}
	err = json.Unmarshal(condenseJ, &z)
	if err != nil {
		fmt.Println("error Unmarshal", err)
		return
	}
	fmt.Println(z)

}
Output:

map[configBool:true configDesc:configuration data]

Types

This section is empty.

Jump to

Keyboard shortcuts

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