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

390
Vistas
How to call the JSON value using nodejs when the value is having hyphen

My JSON value has a value with hyphen like database-name.

I wanted to replace the value of the database-name using below code

    result.databases.database-name = 'ArangoDB';

But it is showing error, How to call the JSON value when the value is having hyphen

Here is a code

const fs = require("fs");
const xml2js = require('xml2js');

fs.readFile("databases.xml", "utf-8", (err, data) => {
    if (err) {
        throw err;
    }

    xml2js.parseString(data, (err, result) => {
        if (err) {
            throw err;
        }

        result.databases.database-name = 'ArangoDB';

       
        const builder = new xml2js.Builder();
        const xml = builder.buildObject(result);

        fs.writeFile('new-databases.xml', xml, (err) => {
            if (err) {
                throw err;
            }

            console.log(`Updated XML is written to a new file.`);
        });

    });
});
about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

You can use this syntax to access object members with a string as the key

result.databases["database-name"] = 'ArangoDB';

Here is the reference

about 4 years ago · Santiago Gelvez Denunciar

0

Try to do like this:

result.databases["database-name"]

That's the way to access properties when you have a hyphen in their key names.

about 4 years ago · Santiago Gelvez 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