mvillafuertem / mapflablup   0.1

MIT License GitHub

Mapflablup is a library to flat ➖ and blowup 🎈 Map Collection

Scala versions: 2.12

Mapflablup

License: MIT codecov CircleCI

Mapflablup is a library to flat ➖ and blowup 🎈 Map Collection

Usage

Please see our scala tests!

Include mapflablup in your project build.sbt
libraryDependencies += "io.github.mvillafuertem" %% "mapflablup" % "0.1"

You can use this library with https://github.com/alibaba/fastjson

val jsonString = """{...}"""

val json = new JSONObject(jsonString)

val resultFlatted = MapFlatten(json).flatten

val resultBlowUp = MapBlowUp(resultFlatted).blowUp

Example

Convert String to JSONObject
val jsonString = """{...}"""
val json = new JSONObject(jsonString)
Given a map as json
{
  "_id": "5c5f1f313fcc6e3084fbe65e",
  "index": 0,
  "guid": "f3b5960b-f3e1-4556-9a5d-f552afe204e7",
  "isActive": true,
  "balance": "$2,809.92",
  "picture": "http://placehold.it/32x32",
  "age": 28,
  "eyeColor": "blue",
  "personalinfo": {
    "name": "Elliott Kaufman",
    "gender": "male",
    "phone": "+1 (858) 421-2925",
    "email": "[email protected]",
    "address": "952 Cropsey Avenue, Tyro, Guam, 1787",
    "company": {
      "name": "SPACEWAX"
    }
  },
  "about": "Labore tempor cupidatat nulla veniam ea veniam aliqua ea. Ad id id dolor enim quis amet irure ad occaecat. Quis enim enim esse mollit. Et officia officia ea consectetur deserunt eiusmod nisi ex culpa consectetur.\r\n",
  "registered": "2015-03-28T06:35:33 -01:00",
  "location": {
    "latitude": 78.370719,
    "longitude": -137.117139
  },
  "greeting": "Hello, Elliott Kaufman! You have 5 unread messages.",
  "favoriteFruit": "strawberry"
}
Apply MapFlat
Map(
    registered -> 2015-03-28T06:35:33 -01:00,
    eyeColor -> blue,
    guid -> f3b5960b-f3e1-4556-9a5d-f552afe204e7,
    favoriteFruit -> strawberry,
    isActive -> true,
    greeting -> Hello, Elliott Kaufman! You have 5 unread messages.,
    picture -> http://placehold.it/32x32,
    personalinfo.name -> Elliott Kaufman,
    personalinfo.gender -> male,
    personalinfo.address -> 952 Cropsey Avenue, Tyro, Guam, 1787,
    personalinfo.company.name -> SPACEWAX,
    personalinfo.phone -> +1 (858) 421-2925,
    personalinfo.email -> [email protected], l
    ocation.latitude -> 78.370719,
    location.longitude -> -137.117139,
    _id -> 5c5f1f313fcc6e3084fbe65e, age -> 28,
    index -> 0, balance -> $2,809.92,
    about -> Labore tempor cupidatat nulla veniam ea veniam aliqua ea. Ad id id dolor enim quis amet irure ad occaecat. Quis enim enim esse mollit. Et officia officia ea consectetur deserunt eiusmod nisi ex culpa consectetur.
)
Apply MapBlowUp
Map(
    registered -> 2015-03-28T06:35:33 -01:00,
    eyeColor -> blue,
    guid -> f3b5960b-f3e1-4556-9a5d-f552afe204e7,
    favoriteFruit -> strawberry,
    isActive -> true,
    greeting -> Hello, Elliott Kaufman! You have 5 unread messages.,
    picture -> http://placehold.it/32x32,
    personalinfo -> Map(
        name -> Elliott Kaufman,
        gender -> male,
        address -> 952 Cropsey Avenue, Tyro, Guam, 1787,
        phone -> +1 (858) 421-2925,
        email -> [email protected],
        company -> Map(
            name -> SPACEWAX
        )
    ),
    location -> Map(
        latitude -> 78.370719,
        longitude -> -137.117139
    ),
    _id -> 5c5f1f313fcc6e3084fbe65e,
    age -> 28,
    index -> 0,
    balance -> $2,809.92,
    about -> Labore tempor cupidatat nulla veniam ea veniam aliqua ea. Ad id id dolor enim quis amet irure ad occaecat. Quis enim enim esse mollit. Et officia officia ea consectetur deserunt eiusmod nisi ex culpa consectetur.
)

License

The MIT License (MIT). Please see License for more information.