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

190
Vistas
How to make a Javascript objects from given JSON data format

Hi I need help understanding how can I create objects from given JSON data:

   {
   "type":"FeatureCollection",
   "features":[

      {
         "type":"Feature",
         "properties":{
            "dbh":6
         },
         "geometry":{
            "type":"Point",
            "coordinates":[
               -79.96474,
               40.46283
            ]
         }
      },
      {
         "type":"Feature",
         "properties":{
            "dbh":2
         },
         "geometry":{
            "type":"Point",
            "coordinates":[
               -80.00949,
               40.42532
            ]
         }
      },
      {
         "type":"Feature",
         "properties":{
            "dbh":12
         },
         "geometry":{
            "type":"Point",
            "coordinates":[
               -79.93531,
               40.42282
            ]
         }
      }

I have done following:

let rsuCountsData = await axios.get('https://rsu-manager-apigateway 5xm3e3o5.uc.gateway.dev/rsucounts');
      this.createGeoJson(rsuCountsData.data); //calling the below function

I created the following function to get the value of count :

createGeoJson(data){
 //geojson={}
 //extract the count from data and store it in a object
 for (let [key, value] of Object.entries(data)) {
  console.log(key, value.count); //key= ip address

}

}

Now inside this function I want to create objects from that above JSON data but I am not sure how to do that because it looks too nested for me figure it out.Below is what I have done.It is mix of pseudo code and JS.Also don't think its correct but can someone help me point in correct direction how I can store these values in JS objects inside createGeoJson function:

     geojson = {}
      geojson.type = "FeatureCollection"
      geojson.features = []

   for key, val in data:
   feat.type = "Feature"
   props.count = val.count
    props.ipAddress = val.ipAddress// this is the key in above function.
   feat.properties = props
   geojson.features.append(feat)

Thanks and appreciate any input

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

0

I would suggest you to use JSON.parse() to convert JSON string to plain JS object.

After that you can iterate it with for...in, loops or any other iterator.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Generally, (after parsing your string via JSON.parse()) you can loop over your Object.feature array with the .forEach function (see MDN documentation).

Not 100% sure what your exact output should be but this looks like a good use case for the .map() function (MDN documentation here). Say, you have your JSON stored in const json, you could do something like:

const json = { ... }
const newArray = json.features.map(el => Object.assign({},{type: el.type, properties: el.properties, geoType: el.geometry.type}));

newArray will be filled with Objects created from empty Objects and the Object.assign() function (MDN documentation)

EDIT: You can also access the index within the .map() function for your counter.

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