flat

package module
v0.0.0-...-0628e9b Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: MIT Imports: 2 Imported by: 0

README

flat

flattens/unflattens map or JSON string

js := `{
  "name": {
    "first_name": "John",
    "last_name": "Doe"
  }
}`
js, err := flat.FlattenJSON(js)
// output: {"name.first_name": "John", "name.last_name": "Doe"}

js, err = flat.UnflattenJSON(js)

NOTE: Use at your own risk ;-)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlattenJSON

func FlattenJSON(str string) (string, error)

FlattenJSON generates a new JSON string with keys flattened.

Given the following JSON string:

{ name: {
   first_name: 'John',
   last_name: 'Doe'
 }}

It generates the following JSON string:

{'name.first_name': 'John', 'name.last_name': 'Doe'}

func UnflattenJSON

func UnflattenJSON(j string) (string, error)

UnflattenJSON unflattens a flat JSON string and returns it to the caller as a new flat JSON string.

Types

type ResultMap

type ResultMap map[string]interface{}

ResultMap map type returned/consumed by the library

func FlattenMap

func FlattenMap(inmap ResultMap) ResultMap

FlattenMap generates a new map with keys flattened.

Given the following JSON string:

  { name: {
     first_name: 'John',
     last_name: 'Doe',
     experiences: [
       {
				year: {start: 2000, end: 2003},
             position: 'programmer',
             company: 'acme'
		  }
     ]
   }}

It generates the following map:

 map[string]interface{} {
   "name.first_name": "John",
   "name.last_name": "Doe",
   "experiences": []map[string]interface{} {
	    map[string]interface{} {
	      "year.start": 2000,
       "year.end": 2003,
       "position": "programmer",
       "company": "acme",
     },
   }
}

func UnflattenMap

func UnflattenMap(inmap ResultMap) ResultMap

UnflattenMap unflattens a flat map.

Jump to

Keyboard shortcuts

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