<commit_before># tinyjson

This is a tiny Go package for reducing repetition and headache in handling JSON.

**Installation**: `go get github.com/bcarrell/tinyjson`

More instructions coming soon.

### Example

	package main

	import (
		"net/http"

		"github.com/bcarrell/tinyjson"
	)

	type person struct {
		Name    string `json:"name"`
		Gender  string `json:"gender"`
		IsHuman bool   `json:"is_human"`
	}

	func main() {
		http.HandleFunc("/", foo)
		http.ListenAndServe(":3000", nil)
	}

	func foo(w http.ResponseWriter, r *http.Request) {
		switch r.Method {
		case "GET": // demonstrates tinyjson.Write
			tricia := &person{
				Name:    "<NAME>",
				Gender:  "Female",
				IsHuman: false,
			}
			tinyjson.Write(w, tricia)
		case "POST": // demonstrates tinyjson.Read
			var person person
			tinyjson.Read(r, &person)
			tinyjson.Write(w, &person) // for the example, just spit it back out
		}
	}


	go run main.go


	❯ curl -i localhost:3000              -- INS --
	HTTP/1.1 200 OK
	Content-Length: 62
	Content-Type: application/json
	Date: Sun, 22 Dec 2013 13:05:49 GMT

	{"name":"<NAME>","gender":"Female","is_human":false}


	❯ curl -X POST -H "Content-Type: application/json" -d '{"name":"<NAME>","gender":"Male","is_human":true}' http://localhost:3000

	{"name":"<NAME>","gender":"Male","is_human":true}<commit_msg>[update] readme<commit_after># tinyjson

This is a tiny Go package for reducing repetition and headache in handling JSON.

**Installation**: `go get github.com/bcarrell/tinyjson`

More instructions coming soon.

### Example

	package main

	import (
		"net/http"

		"github.com/bcarrell/tinyjson"
	)

	type person struct {
		Name    string `json:"name"`
		Gender  string `json:"gender"`
		IsHuman bool   `json:"is_human"`
	}

	func main() {
		http.HandleFunc("/", foo)
		http.ListenAndServe(":3000", nil)
	}

	func foo(w http.ResponseWriter, r *http.Request) {
		switch r.Method {
		case "GET": // demonstrates tinyjson.Write
			tricia := &person{
				Name:    "<NAME>",
				Gender:  "Female",
				IsHuman: false,
			}
			tinyjson.Write(w, tricia)
		case "POST": // demonstrates tinyjson.Read
			var person person
			tinyjson.Read(r, &person)
			tinyjson.Write(w, &person) // for the example, just spit it back out
		}
	}

<!-- separate -->

	go run main.go

<!-- separate -->

	❯ curl -i localhost:3000              -- INS --
	HTTP/1.1 200 OK
	Content-Length: 62
	Content-Type: application/json
	Date: Sun, 22 Dec 2013 13:05:49 GMT

	{"name":"<NAME>","gender":"Female","is_human":false}

<!-- separate -->

	❯ curl -X POST -H "Content-Type: application/json" -d '{"name":"<NAME>","gender":"Male","is_human":true}' http://localhost:3000

	{"name":"<NAME>","gender":"Male","is_human":true}
{'fraction_non_alphanumeric': 0.16433823529411765, 'fraction_numerical': 0.022794117647058822, 'mean_word_length': 3.4533551554828152, 'pattern_counts': {'":': 24, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1287172', 'n_tokens_mistral': 1099, 'n_tokens_neox': 921, 'n_words': 247}