#flatten #json #serde-json #json-object #elasticsearch #elastic #search

bin+lib flatten-serde-json

Flatten serde-json objects like elastic search

1 unstable release

0.1.0 Feb 23, 2022

#2657 in Command line utilities

Download history 109/week @ 2024-01-14 230/week @ 2024-01-21 106/week @ 2024-01-28 216/week @ 2024-02-04 408/week @ 2024-02-11 359/week @ 2024-02-18 269/week @ 2024-02-25 442/week @ 2024-03-03 388/week @ 2024-03-10 403/week @ 2024-03-17 219/week @ 2024-03-24 532/week @ 2024-03-31 570/week @ 2024-04-07 330/week @ 2024-04-14 558/week @ 2024-04-21 317/week @ 2024-04-28

1,787 downloads per month

WTFPL license

10KB
241 lines

Flatten serde Json

This crate flatten serde_json Object in a format similar to elastic search.

Examples

There is nothing to do

{
  "id": "287947",
  "title": "Shazam!",
  "release_date": 1553299200,
  "genres": [
    "Action",
    "Comedy",
    "Fantasy"
  ]
}

Flattens to:

{
  "id": "287947",
  "title": "Shazam!",
  "release_date": 1553299200,
  "genres": [
    "Action",
    "Comedy",
    "Fantasy"
  ]
}

Objects

{
  "a": {
    "b": "c",
    "d": "e",
    "f": "g"
  }
}

Flattens to:

{
  "a.b": "c",
  "a.d": "e",
  "a.f": "g"
}

Array of objects

{
  "a": [
    { "b": "c" },
    { "b": "d" },
    { "b": "e" },
  ]
}

Flattens to:

{
  "a.b": ["c", "d", "e"],
}

Array of objects with normal value in the array

{
  "a": [
    42,
    { "b": "c" },
    { "b": "d" },
    { "b": "e" },
  ]
}

Flattens to:

{
  "a": 42,
  "a.b": ["c", "d", "e"],
}

Array of objects of array of objects of ...

{
  "a": [
    "b",
    ["c", "d"],
    { "e": ["f", "g"] },
    [
        { "h": "i" },
        { "e": ["j", { "z": "y" }] },
    ],
    ["l"],
    "m",
  ]
}

Flattens to:

{
  "a": ["b", "c", "d", "l", "m"],
  "a.e": ["f", "g", "j"],
  "a.h": "i",
  "a.e.z": "y",
}

Collision between a generated field name and an already existing field

{
  "a": {
    "b": "c",
  },
  "a.b": "d",
}

Flattens to:

{
  "a.b": ["c", "d"],
}

Dependencies

~360–760KB
~17K SLoC