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

134
Vistas
Convert key value object to json - javascript

Hey All I have this object that I try to convert to json. I tried

reportDropDownsJson2 =  JSON.parse('{"' + reportDropDownsJson.replace(/&/g, '","').replace(/=/g,'":"') + '"}', function(key, value) { return key===""?value:decodeURIComponent(value) });
            reportDropDownsJson['downloadcsv'] = true; 

and the result is:

TypeError: reportDropDownsJson.replace is not a function

this is the object (called reportDropDownsJson) that I try to convert to json

ad_type: ""
agency_id[]: ""
auction_type: ""
brand_id[]: ""
campaign: ""
campaign-drop: ""
column_filter[]: (23) ['Timestamp', 'Date', 'Hour', 'Brand', 'Requests', 'Bids', 'Bid %', 'Wins', 'Win %', 'Fill %', 'Imps Pixel', 'Revenue $', 'Cost $', 'eCPM', 'Sales Person', 'AdOPS Person', 'Account Manager Person', 'IVT Provider 1', 'Viewability Provider 1', 'VCR', 'CTR', 'VTR', 'Campaign']
deal_id[]: ""
deal_personnel[]: ""
deal_type[]: ""
device_type: ""
dsp_id[]: ""
edit_saved_report: ""
end_date: "2022-02-16"
frozen_filter[]: "Timestamp"
group_by[]: ""
interval: "hourly"
media_type: ""
office_country[]: "All"
pub_id[]: ""
ssp_id[]: ""
start_date: "2022-02-16"
timezone: "US/Eastern"
_token: "Fixv8PZsW6vsavjysdbVcxDsedqy8tiw7s7vUVBp"
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

We cant use replace on objects.It can be used on strings.If you want to replace the values of object you can loop through object and use replace on single values.

Yoc can try this method to get values of an object:

for (const [key, value] of Object.entries(reportDropDownsJson)) {
  console.log(`${key}: ${value}`);
}

Inside for loop you can use value.replace() and do whatever logic

about 4 years ago · Juan Pablo Isaza Denunciar

0

Replace cannot be used in objects.

To iterate the keys and values inside an object, you can do this:

Object.entries(reportDropDownsJson).forEach(([key, value]) => {
    // Do whatever you need to write out the json with the "key" and "value" pair
});
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