npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-key-translator

v0.4.1

Published

Translate JSON keys between languages using AI

Downloads

12

Readme

JSON Key Translator

A Node.js library to translate JSON keys between languages.

Features

  • Translate JSON keys from English to any language
  • Support for deep nested JSON structures
  • DeepSeek AI integration for high-quality translations
  • Fully typed with TypeScript
  • Simple API for easy integration

Installation

npm install json-key-translator

Usage

Basic Usage

import { translateKeys, transformJson } from 'json-key-translator';

// Your JSON object with English keys
const englishJson = {
  user: {
    firstName: 'John',
    lastName: 'Doe',
    address: {
      street: '123 Main St',
      city: 'Anytown'
    }
  }
};

// Translate the keys
const result = await translateKeys(englishJson, {
  sourceLanguage: 'en',
  targetLanguage: 'zh'
});

// The result contains:
// 1. keyMap: Mapping between original and translated keys
// 2. translatedJson: The JSON with translated keys

console.log(result.keyMap);
// Example output:
// {
//   user: '用户',
//   firstName: '名',
//   lastName: '姓',
//   address: '地址',
//   street: '街道',
//   city: '城市'
// }

console.log(result.translatedJson);
// Example output:
// {
//   用户: {
//     名: 'John',
//     姓: 'Doe',
//     地址: {
//       街道: '123 Main St',
//       城市: 'Anytown'
//     }
//   }
// }

Using DeepSeek AI for Translation

import { translateKeys, createDeepSeekTranslator } from 'json-key-translator';

// Create a DeepSeek translator with your API key
const deepSeekTranslator = createDeepSeekTranslator({
  apiKey: 'your-deepseek-api-key'
});

// Your JSON object with English keys
const englishJson = {
  user: {
    firstName: 'John',
    lastName: 'Doe'
  }
};

// Translate using DeepSeek
const result = await translateKeys(englishJson, {
  sourceLanguage: 'en',
  targetLanguage: 'zh',
  translationFn: deepSeekTranslator
});

console.log(result.translatedJson);

Working with Existing Key Mappings

If you already have a key mapping that you want to extend:

import { translateKeys } from 'json-key-translator';

// Existing key mapping
const existingKeyMap = {
  user: '用户',
  firstName: '名'
};

// New JSON with additional keys
const newJson = {
  user: {
    firstName: 'John',
    lastName: 'Doe',
    email: '[email protected]'
  }
};

// Translate, extending the existing key map
const result = await translateKeys(newJson, {
  sourceLanguage: 'en',
  targetLanguage: 'zh',
  keyMap: existingKeyMap
});

// The result.keyMap will include the original mappings plus new ones

Manually Transforming JSON

If you have a key mapping and want to apply it to a JSON object:

import { transformJson } from 'json-key-translator';

const keyMap = {
  user: '用户',
  firstName: '名',
  lastName: '姓'
};

const englishJson = {
  user: {
    firstName: 'John',
    lastName: 'Doe'
  }
};

const chineseJson = transformJson(englishJson, keyMap);

console.log(chineseJson);
// {
//   用户: {
//     名: 'John',
//     姓: 'Doe'
//   }
// }

API Reference

translateKeys(json, options)

Translates the keys of a JSON object.

Parameters:

  • json (Object): The JSON object to translate
  • options (TranslationOptions): Options for translation
    • sourceLanguage (string): Source language code (default: 'en')
    • targetLanguage (string): Target language code (default: 'zh')
    • translationFn (Function): Custom translation function
    • keyMap (Object): Existing key map to extend
    • mode (string): 'data' (default) or 'schema'

Returns:

  • KeyMappingResult: Object containing the key mapping and translated JSON

transformJson(json, keyMap, options)

Applies a key mapping to transform a JSON object.

Parameters:

  • json (Object): The JSON object to transform
  • keyMap (Object): Mapping of original keys to translated keys
  • options (TransformOptions): Options for transformation
    • deep (boolean): Whether to transform nested objects (default: true)
    • transformArrays (boolean): Whether to transform array items (default: true)

Returns:

  • Transformed JSON object

createDeepSeekTranslator(config)

Creates a translation function that uses DeepSeek AI.

Parameters:

  • config (DeepSeekConfig): Configuration for DeepSeek AI
    • apiKey (string): DeepSeek API key
    • apiEndpoint (string): API endpoint (optional)
    • model (string): Model to use (optional)
    • temperature (number): Generation temperature (optional)

Returns:

  • Translation function compatible with translateKeys

License

MIT