github.com/huandu/go@v0.0.0-20151114150818-04e615e41150/doc/progs/json5.go (about)

     1  // Copyright 2012 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"encoding/json"
     9  	"log"
    10  	"os"
    11  )
    12  
    13  func main() {
    14  	dec := json.NewDecoder(os.Stdin)
    15  	enc := json.NewEncoder(os.Stdout)
    16  	for {
    17  		var v map[string]interface{}
    18  		if err := dec.Decode(&v); err != nil {
    19  			log.Println(err)
    20  			return
    21  		}
    22  		for k := range v {
    23  			if k != "Name" {
    24  				delete(v, k)
    25  			}
    26  		}
    27  		if err := enc.Encode(&v); err != nil {
    28  			log.Println(err)
    29  		}
    30  	}
    31  }