---
title: "Importing JSON with custom types in TypeScript"
url: https://daily.dev/posts/importing-json-with-custom-types-in-typescript-at22hip0o
source_url: https://www.damirscorner.com/blog/posts/20260522-ImportingJsonWithCustomTypesInTypescript.html
type: article
source: "Damir's Corner"
published: 2026-05-31T07:45:55.545Z
updated: 2026-05-31T08:59:37.579Z
tags: ["typescript"]
reading_time: 3
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Importing JSON with custom types in TypeScript

**[Damir's Corner](https://daily.dev/sources/damirscorner)** · 3 min read · 0 upvotes · 0 comments

## Summary

When importing JSON files in TypeScript, the compiler infers types automatically via `resolveJsonModule`, but the inferred types can be overly specific. For example, a dictionary with string keys gets typed with literal property names rather than `Record<string, string>`. The solution is to use the `allowArbitraryExtensions` compiler option and create a `.d.json.ts` declaration file with the same base name as the JSON file, allowing you to define your own types. This overrides the compiler's inferred types, but requires you to ensure the JSON data actually matches your declared types to avoid runtime errors.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.damirscorner.com/blog/posts/20260522-ImportingJsonWithCustomTypesInTypescript.html>

## Similar posts on daily.dev

- [Native JSON modules are finally real](https://daily.dev/posts/native-json-modules-are-finally-real-zkdi3tmao) · Matt Smith · 23 upvotes · 2 comments

---

Tags: [#typescript](https://daily.dev/tags/typescript)

[View this post on daily.dev](https://daily.dev/posts/importing-json-with-custom-types-in-typescript-at22hip0o)
