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

138
Vistas
How to extract Name from a JSON Name/Value pair and append to a TextField

I have JSON which looks like this:

{
  "Id": 1,
  "Title": "Data about John Doe",
  "Comments": "Some text goes here",
  "UpdatedBy": "John Doe",
  "UpdateDate": "Apr 14 2022 12:00AM"
}

I want to map this JSON to MUI TextFields with the names of the name/value pairs as the TextField labels, and the values as the TextField values. I also need to be able to edit the values.

This is my array of data:

const [singleSizing, setSingleSizing] = useState("");
const fetchSizingData = async (intake_id, sizing_id) => {
  setSingleSizing(
    await fetch(`/api/fiscalyears/FY2023/intakes/${params.id}/details/questions`).then((response) =>
                response.json()
            )
  );
};

These are the Text Fields I am using:

<TextField
  value={}
  label={}
/>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Assuming singleSizing is one JSON object. If not, map over first:

You can use Object.entries to extract the key/value pair from the object and then .map() over the entries to create the components.

// ...

  return Object.entries(singleSizing).map(sizingEntry => {
      const [label, value] = sizingEntry; // e.g. ['Title', 'Data about John Doe']
      
      return <TextField label={label} value={value} />
  });

// ...

To edit the values, look into a MUI form components or another form library and consider changing the shape of the state to make updates easier.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use .map & Object.keys

 {
     
      
        Object.key(singleSizing).map(key => ( 
          <TextField 
              value = {
                obj[key]
              }
              label = {
                key
              }
            />
        ))
      
 }


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