Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
How can I take a group of nested JSON objects and append their data to an editable text field?

I have a group of nested JSON objects which I need to append to a text field. There are 6 objects and I don't want to hard code 6 text fields. I have used the .map functionality in the past, but I cannot get it to work in this case.

const [questions, setQuestions] = useState('');
const fetchQuestions = async () => {
    setQuestions( await fetch(`/fiscalyears/FY2023/intakes/${params.id}/details/questions`)
                             .then((response) => response.json())
    );
};

useEffect(() => {
    fetchQuestions();
}, []);

In side my return statement:

{questions?.map((row) => (
    <TextField
        className="text-field"
        value={row?.Value || ''}
        variant="outlined"
        margin="normal"
        label={row['FieldName']}
    />
))}

Here is a shortened version of my JSON:

{
  "Consulting": [
    {
      "Question": null,
      "Response": null
    }
  ],
  "FED": [
    {
      "Question": "1. Is there any impact to the region applications?",
      "Response": "No"
    },
    {
      "Question": "2. If number 1 is \"Yes\", then are any of the below applications being 
       impacted?",
      "Response": "No"
    },
    {
      "Question": "3. Are you changing data structure? \r\n",
      "Response": null
    }
  ],
  "IPE": [
    {
      "Question": "1. Do you need compute (servers), storage, databases, and/or platform capacity for your effort?",
      "Response": "Yes"
    },
    {
      "Question": "2. If yes, please describe:",
      "Response": "I need servers"
    },
    {
      "Question": "3. Do you need Database Services?\r\n",
      "Response": null
    }
  ]
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use map method only for arrays. For iterate through object, you can use

Object.keys(questions).map(function(key, index) {
  //do something here
})

Otherwise you can use a for cycle but i dislike it

for (var key in questions) {
  if (questions.hasOwnProperty(key)) {
    // use questions[key]
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda