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',
// }],
// },
// }
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. :)
Top comments (0)