Introducing ts-jackson, a typescript library to deserialize/serialize deeply nested json structures.

eljoy

Ilias Gazdaliev

Posted on May 10, 2022

Introducing ts-jackson, a typescript library to deserialize/serialize deeply nested json structures.

ts-jackson is a json seralization library aimed to effortlessly handle serialization/deserialization of deeply nested json structures.

For example:

const jsonData = {
  images: {
    items: [
      {
        height: 300,
        url:
          'https://i.scdn.co/image/ab67616d0000b27380368f0aa8f90c51674f9dd2',
        width: 300,
      },
      {
        height: 640,
        url:
          'https://i.scdn.co/image/ab67616d00001e0280368f0aa8f90c51674f9dd2',
        width: 640,
      },
    ],
  },
}

@Serializable()
class Playlist {
  @JsonProperty('images.items[1]')
  readonly backgroundImage: Image
}

const deserialized = deserialize(jsonData, Playlist)
// Playlist {
//   backgroundImage: Image {
//     height: 640,
//     width: 640,
//     url: 'https://i.scdn.co/image/ab67616d00001e0280368f0aa8f90c51674f9dd2'
//   }
// }
const serialized = serialize(deserialized)
// {
//   images: {
//     items: [undefined, {
//       height: 640,
//       width: 640,
//       url: 'https://i.scdn.co/image/ab67616d00001e0280368f0aa8f90c51674f9dd2',
//     }],
//   },
// }
Enter fullscreen mode Exit fullscreen mode

It uses Lodash _.get/_.set to resolve property paths and supports every pattern provided by Lodash.

You can check out the full api here:
https://github.com/Eljoy/ts-jackson

Every feedback is truly welcomed. :)

💖 💪 🙅 🚩
eljoy
Ilias Gazdaliev

Posted on May 10, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related