Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
Object loaded from json file has its values assigned to a property called default

In my node + TypeScript project, I have a json file with some default config. Let's say it looks like this:

{
  prop1: 123,
  prop2: 123
}

And I'm loading values from this file somewhere along the way like this:

import * as defconfig from '../configuration/config.json';

And when I'm checking it in the console I see this output:

{
  prop1: [Getter],
  prop2: [Getter],
    default: {
      prop1: 123,
      prop2: 123
   }
}

And also if I try to override this object with spread operator or Object.assign, the result is following:

const options = {
  prop1: 321,
  prop2: 321
};

console.log({...defconfig, ...options});

//OR

console.log(Object.assign(defconfing, options));

//produces

{
  prop1: 321,
  prop2: 321,
  default: {
    prop1: 123,
    prop2: 123
  }
}

Can anyone explain where is the default coming from and how to get rid of it?

The same code works perfectly fine when not using .json file but defining config with a normal object, but the issue is that I have to use the file.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

According to the latest node versions, JSON files cannot be read directly as modules. Unless you use --experimental-json-modules flag while running.

A solution would be to use commonjs (for that you would need to change file extension to .cjs) method require which will be able to do the task or you can use fs module to read JSON string and then parse.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda