{"modulePath":"github.com/AliceO2Group/Control","version":"v1.51.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package flatten\n\nFlatten makes flat, one-dimensional maps from arbitrarily nested ones.\n\nIt turns map keys into compound names, in four styles: dotted (\\`a.b.1.c\\`), path-like (\\`a/b/1/c\\`), Rails (\\`a\\[b]\\[1]\\[c]\\`), or with underscores (\\`a\\_b\\_1\\_c\\`).  It takes input as either JSON strings or Go structures.  It knows how to traverse these JSON types: objects/maps, arrays and scalars.\n\nYou can flatten JSON strings.\n\n\tnested := `{\n\t  \"one\": {\n\t    \"two\": [\n\t      \"2a\",\n\t      \"2b\"\n\t    ]\n\t  },\n\t  \"side\": \"value\"\n\t}`\n\n\tflat, err := flatten.FlattenString(nested, \"\", flatten.DotStyle)\n\n\t// output: `{ \"one.two.0\": \"2a\", \"one.two.1\": \"2b\", \"side\": \"value\" }`\n\nOr Go maps directly.\n\n\tnested := map[string]interface{}{\n\t\t\"a\": \"b\",\n\t\t\"c\": map[string]interface{}{\n\t\t\t\"d\": \"e\",\n\t\t\t\"f\": \"g\",\n\t\t},\n\t\t\"z\": 1.4567,\n\t}\n\n\tflat, err := flatten.Flatten(nested, \"\", flatten.RailsStyle)\n\n\t// output:\n\t// map[string]interface{}{\n\t//\t\"a\":    \"b\",\n\t//\t\"c[d]\": \"e\",\n\t//\t\"c[f]\": \"g\",\n\t//\t\"z\":    1.4567,\n\t// }\n\n## Variables\n\n```go\nvar NotValidInputError = errors.New(\"Not a valid input: map or slice\")\n```\nNested input must be a map or slice\n\n## Functions\n\n```go\nfunc Flatten(nested map[string]interface{}, prefix string, style SeparatorStyle) (map[string]interface{}, error)\n```\nFlatten generates a flat map from a nested one.  The original may include values of type map, slice and scalar, but not struct.  Keys in the flat map will be a compound of descending map keys and slice iterations. The presentation of keys is set by style.  A prefix is joined to each key.\n\n```go\nfunc FlattenString(nestedstr, prefix string, style SeparatorStyle) (string, error)\n```\nFlattenString generates a flat JSON map from a nested one.  Keys in the flat map will be a compound of descending map keys and slice iterations.  The presentation of keys is set by style.  A prefix is joined to each key.\n\n## Types\n\n```go\ntype SeparatorStyle int\n```\nThe presentation style of keys.\n\n```go\nconst (\n\n\t// Separate nested key components with dots, e.g. \"a.b.1.c.d\"\n\tDotStyle SeparatorStyle\n\n\t// Separate with path-like slashes, e.g. a/b/1/c/d\n\tPathStyle\n\n\t// Separate ala Rails, e.g. \"a[b][c][1][d]\"\n\tRailsStyle\n\n\t// Separate with underscores, e.g. \"a_b_1_c_d\"\n\tUnderscoreStyle\n)\n```\n\n","path":"github.com/AliceO2Group/Control/occ/peanut/flatten","name":"flatten","synopsis":"Flatten makes flat, one-dimensional maps from arbitrarily nested ones.","isRedistributable":true}
