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

260
Vistas
How can you integrate a variable in a JSON path in JavaScript

First of all, it's connecting to a url and just sanitizing it all in the Front-End. The Hypixel API works so, that you take the api url for the wanted request, in this case api.hypixel.net/player?name=USERNAME&key=APIKEY, and get back a big JSON file, which my code should sanitize. So, if you're using the Hypixel API, yeah you're sending the API-Key through the browser, but that is a security flaw in the Hypixle API and not in my code. The sole purpose of my code is to learn more about JavaScript an show it to others.

I'm working on an API access to the Hypixel API.
This gets me a JSON, in which I want to get a specific game, that was inputted in a field an is saved in a dict.

I'm trying to integrate this like this (console.log is only for test purposes, until I give back the data to HTML):

let values = Array.from(document.querySelectorAll('#apiForm input'))
    .reduce((acc, input) => {
        return { ...acc, [input.id]: input.value };
    }, {})

fetch(`https://api.hypixel.net/player?name=${values.name}&key=${values.key}`)
    .then(result => result.json())
    .then(result => {
        if (result.success) {
            if (values.game in result.player.stats) {
                console.log(result.player.stats.$(values.game)) //not working
            } else {
                console.log(result.player.stats)
                console.log('Game not available or not played yet')
            }
        } else {
            console.log('Something went wrong, please check your name and API-Key or try again later')
        }
    })

How can I do this here?

The API-Form looks like this: Form

And the JSON file looks like this: JSON file

So when I input Bedwars for example, the path I want should result in result.player.stats.Bedwars:

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

0

Replace result.player.stats.$(values.game) with

result.player.stats[values.game]

Also, when putting user input into URI paths, sanitize it with encodeURIComponent or build the query string with new URLSearchParams({ ...props }).toString().

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