Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

88
Views
Creating typescript interface from JSON object

Is there a way to import a JSON object into a Typescript program so that it is automatically strongly typed and constant?

So if I have this code in person.json:

{
  "name": "Steven",
  "eyeColor": "brown"
}

I want to be able to import it to a Typescript program as such:

// personTest.ts
const person = require('person.json');
console.log(person.name); // This should be fine
console.log(person.age);  // This should cause a compile-time error, because this property is not defined
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

add this on tsconfig.json

{

   ... //prev code

   "resolveJsonModule": true, 

}

then you can use ESM modules to import json file and it will be auto typed the object values

import person from './person.json' //be sure from the json path
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!