
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@jeroenhuinink/tsmapper
Advanced tools
Library to map JSON (API responses) to typed objects for Typescript.
I like types, because when you have type information your IDE and other tools can help you avoid mistakes. Because I like types, I also like to use Typescript for frontend and backend development. A lot of what we do as either frontend and backend developers is interpret bodies sent as as part of (REST) API requests or responses. Because REST is in itself untyped and the request and response body for an HTTP request can contain arbitrary data, I like to not make any assumptions about the types of data and if data comes in an unexpected format you should fail fast to avoid hard to track errors down the line.
This library helps you interpret (map) API responses and return a guaranteed typescript (interface) type.
This library took inspiration from mappet and the yargs type definitions.
null makes the field optional.npm install @jeroenhuinink/tsmapper
or
yarn add @jeroenhuinink/tsmapper
You can call the createMapper function to create a mapper. The function has an optional string parameter for the mapper name. This will be included in error messages. The create mapper has a mapper.map(source) function that will map a source JSON to a target as defined by the fields added to the mapper..
You can use .field(name, options) to add field declarations to the mapper. The name is the field name that is should have in the target. In the options you can specify a key for the name that the field has in the source. You can also specify default values and modifier functions. If the type can not be derived from the default value or the modifier function you can also specify a type. Otherwise a type of unknown will be drived.
import {createMapper} from '@jeroenhuinink/tsmapper';
const userMapper = createMapper('UserMapper')
.field('id', { key: 'userId', type: 'number' })
.field('givenName', { type: 'string' })
.field('familyName', { type: 'string' })
.field('email', { type: 'string' })
.field('isAdmin', { type: 'boolean' });
const user = userMapper.map({
userId: '12',
givenName: 'Jeroen',
familyName: 'Huinink',
email: 'jeroen.huinink@example.com',
isAdmin: false,
});
You can use type User = ReturnType<typeof userMapper.map> to get the type of the target.
More usage examples can be found in the examples subdirectory of the tests directory.
FAQs
JSON to Typescript object mapper
The npm package @jeroenhuinink/tsmapper receives a total of 67 weekly downloads. As such, @jeroenhuinink/tsmapper popularity was classified as not popular.
We found that @jeroenhuinink/tsmapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.