I have a JSON like this:
{ "id_document" : "12345679", "name" : "John SMmith", "value" : "127,30" }
I would like to change the "value" field to a Double/Number, like this:
{ "id_document" : "12345679", "name" : "John SMmith", "value" : 127.30 }
The problem is that I have a lot of JSON data, eg 70k lines. So I need a way to automate this. Does anyone have any ideias?
Resolution can be made in any language. I was trying NodeJS.
Thanks for the help guys.
EDIT:
My JSON file is something like:
{"DESPESA": [{"sgPartido": "DEM", "numMes": 1, "txtCNPJCPF": "03625917000170", "vlrGlosa": "0", "txNomeParlamentar": "ABEL MESQUITA JR.", "sgUF": "RR", "nuCarteiraParlamentar": 1, "vlrDocumento": "4007,06", "nuDeputadoId": 3074, "numSubCota": 3, "txtDescricaoEspecificacao": "Veículos Automotores", "txtPassageiro": null, "datEmissao": null, "codLegislatura": 55, "vlrRestituicao": "0", "numParcela": 0, "txtDescricao": "COMBUSTÍVEIS E LUBRIFICANTES.", "txtNumero": "4339", "numEspecificacaoSubCota": 1, "txtFornecedor": "B.B. PETROLEO LTDA", "numLote": 1354058, "indTipoDocumento": 0, "idecadastro": 178957, "numAno": 2017, "txtTrecho": null, "numRessarcimento": 5711, "vlrLiquido": "4007,06", "ideDocumento": 6196889, "nuLegislatura": 2015}, ...70k lines with objects like this and the end}
EDIT: I did guys, the result was that:
fs = require('fs');
var in_file = 'in.json';
var out_file = 'out.json'
fs.readFile(in_file, 'utf8', function(err, data) {
data = JSON.parse(data);
for(let i in data.DESPESA) {
let despesa = data.DESPESA[i];
let valor = despesa.vlrDocumento.replace(',', '.');
data.DESPESA[i].vlrDocumento = parseFloat(valor);
}
fs.writeFile(out_file, JSON.stringify(data), function(err) {
if (err) throw err;
console.log('The file has been saved!');
});
});
thanks for que the help, the answers made the difference.