flatjson

package module
v0.0.0-...-86044f1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2015 License: BSD-2-Clause Imports: 2 Imported by: 18

README

flatjson Build Status

flatjson is a Go package for collapsing structs into a flat map, which can then be JSON encoded. The map values are pointers to the original struct fields, so it does not need to be regenerated when the values are updated.

Example use case:

{
  "Connections": {
    "Open": 2,
    "Accepted": 4
  },
  "ResponseTime": {
    "P50": 0.045775,
    "P90": 0.074299,
    "P95": 0.096207
  },
  "Peers.IPv6": {
    "Current": 0,
    "Joined": 0,
    "Left": 0,
    "Reaped": 0,
    "Completed": 0,
    "Seeds": {
      "Current": 0,
      "Joined": 0,
      "Left": 0,
      "Reaped": 0
    }
  },
  "Memory": {
    "Alloc": 682208,
    "TotalAlloc": 1032488,
    "Sys": 5441784,
    "Lookups": 28,
    "Mallocs": 3326,
    "Frees": 2567
  }
}

is instead serialized as:

{
  "Connections.Accepted": 4,
  "Connections.Open": 2,
  "Memory.Alloc": 682208,
  "Memory.Frees": 2567,
  "Memory.Lookups": 281,
  "Memory.Mallocs": 3326,
  "Memory.Sys": 5441784,
  "Memory.TotalAlloc": 1032488,
  "Peers.IPv6.Completed": 0,
  "Peers.IPv6.Current": 0,
  "Peers.IPv6.Joined": 0,
  "Peers.IPv6.Left": 0,
  "Peers.IPv6.Reaped": 0,
  "Peers.IPv6.Seeds.Current": 0,
  "Peers.IPv6.Seeds.Joined": 0,
  "Peers.IPv6.Seeds.Left": 0,
  "Peers.IPv6.Seeds.Reaped": 0,
  "ResponseTime.P50": 0.045775,
  "ResponseTime.P90": 0.074299,
  "ResponseTime.P95": 0.096207
}

Documentation

Overview

Package flatjson implements a means of converting a struct into a flattened map suitable for JSON encoding. The values in the map are pointers to the original struct fields, so the map can be generated once and encoded whenever the underlying values change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map map[string]interface{}

func Flatten

func Flatten(val interface{}) Map

Flatten returns the Map representation of val.

Jump to

Keyboard shortcuts

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