DEV Community

Discussion on: Strongly Typed JSON in TypeScript

Collapse
 
dipayansukul profile image
Dipayan Sukul

Any good practice to load 25mb data from postgres db using nestjs?

Collapse
 
nickytonline profile image
Nick Taylor

The reason it’s a compiler option is because it can slow down the compiler for large data. You might be better off using a codegen tool to generate the types for that large JSON file.

Read big JSON files? #42761

Bug Report

🔎 Search Terms

"large json files"

Problem

None of the predefined sections are relevant here.

I'm trying to get types from a JSON file using resolveJsonModule. I'm using VS Code to do everything here. My JSON file is 4.9 MB and 200k lines. When I try to inspect the result of require('./big-file.json), it says {}. But it works great for another smaller file, albeit a bit slow.

Not sure if this is relevant or not, but it also fails for this big file in quicktype and works for the slightly smaller file. I assumed they're using TypeScript's parser/compiler under the hood, which would explain it. If they're not, then maybe it's a Node.js limitation that it's coming across.

To be clear, the require call itself works fine and returns a valid JSON object. So it might not be a Node.js memory limitation issue. But it might be one if TypeScript is more than doubling the memory by all its type analysis, or by duplicating substrings, etc.

Just some thoughts. I have no idea what's going on. All I know is that I was hoping VS Code would analyze my JSON files for me, but it's only working on some files.

Specifically this comment.