<commit_before>flatten
=======

[![GoDoc](https://godoc.org/github.com/jeremywohl/flatten?status.png)](https://godoc.org/github.com/jeremywohl/flatten)
[![Build Status](https://travis-ci.org/jeremywohl/flatten.svg?branch=master)](https://travis-ci.org/jeremywohl/flatten)

Flatten makes flat, one-dimensional maps from arbitrarily nested ones, from JSON strings or Go native structures.  It can handles interior maps, slices and scalars.

Intended for JSON APIs, flatten operates on interior maps, slices and scalars.  Flat, compound
keys are generated in either dotted style (e.g. a.b.1.c) or Rails-like (e.g. a[b][1][c]).

You can flatten JSON strings.

    nested := `{
      "one": {
        "two": [
          "2a",
          "2b"
        ]
      },
      "side": "value"
    }`
    
    flat, err := FlattenString(nested, "", DOT_STYLE)
    
    // output: `{ "one.two.0": "2a", "one.two.1": "2b", "side": "value" }`

Or Go maps directly.

    t := map[string]interface{}{
       "a": "b",
       "c": map[string]interface{}{
           "d": "e",
           "f": "g",
       },
       "z": 1.4567
    }
    
    flat, err := Flatten(nested, "", RAILS_STYLE)
    
    // output:
    // map[string]interface{}{
    //  "a":    "b",
    //  "c[d]": "e",
    //  "c[f]": "g",
    //  "z":    1.4567,
    // }

See [godoc](https://godoc.org/github.com/jeremywohl/flatten) for API.<commit_msg>Go formatting in README.<commit_after>flatten
=======

[![GoDoc](https://godoc.org/github.com/jeremywohl/flatten?status.png)](https://godoc.org/github.com/jeremywohl/flatten)
[![Build Status](https://travis-ci.org/jeremywohl/flatten.svg?branch=master)](https://travis-ci.org/jeremywohl/flatten)

Flatten makes flat, one-dimensional maps from arbitrarily nested ones, from JSON strings or Go native structures.  It can handles interior maps, slices and scalars.

Intended for JSON APIs, flatten operates on interior maps, slices and scalars.  Flat, compound
keys are generated in either dotted style (e.g. a.b.1.c) or Rails-like (e.g. a[b][1][c]).

You can flatten JSON strings.

```go
nested := `{
  "one": {
    "two": [
      "2a",
      "2b"
    ]
  },
  "side": "value"
}`

flat, err := FlattenString(nested, "", DOT_STYLE)

// output: `{ "one.two.0": "2a", "one.two.1": "2b", "side": "value" }`
```

Or Go maps directly.

```go
t := map[string]interface{}{
   "a": "b",
   "c": map[string]interface{}{
       "d": "e",
       "f": "g",
   },
   "z": 1.4567
}

flat, err := Flatten(nested, "", RAILS_STYLE)

// output:
// map[string]interface{}{
//  "a":    "b",
//  "c[d]": "e",
//  "c[f]": "g",
//  "z":    1.4567,
// }
```

See [godoc](https://godoc.org/github.com/jeremywohl/flatten) for API.
{'fraction_non_alphanumeric': 0.20386186409209062, 'fraction_numerical': 0.013367991088005942, 'mean_word_length': 2.821276595744681, 'pattern_counts': {'":': 30, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, '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': '6104817', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1029, 'n_words': 228}