hughsk / flat

:steam_locomotive: Flatten/unflatten nested Javascript objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conversion Problem

dayres opened this issue · comments

commented

It may just be me doing something stupid however I'm converting the following:

{ app_preferences: { test: 1 }, settings: { network: { appnetwork: { device: '/dev/eth1' }, devnetwork: { device: '/dev/eth0' } } } }

The object flatten is producing is this:

{"0":123,"1":10,"2":32,"3":110,"4":100,"5":109,"6":95,"7":112,"8":114,"9":101,"10":102,"11":101,"12":114,"13":101,"14":110,"15":99,"16":101,"17":115,"18":58,"19":32,"20":123,"21":10,"22":32,"23":32,"24":32,"25":116,"26":101,"27":115,"28":116,"29":58,"30":32,"31":49,"32":10,"33":32,"34":125,"35":44,"36":10,"37":32,"38":115,"39":101,"40":116,"41":116,"42":105,"43":110,"44":103,"45":115,"46":58,"47":32,"48":123,"49":10,"50":32,"51":32,"52":32,"53":110,"54":101,"55":116,"56":119,"57":111,"58":114,"59":107,"60":58,"61":32,"62":123,"63":10,"64":32,"65":32,"66":32,"67":32,"68":32,"69":110,"70":100,"71":109,"72":110,"73":101,"74":116,"75":119,"76":111,"77":114,"78":107,"79":58,"80":32,"81":123,"82":10,"83":32,"84":32,"85":32,"86":32,"87":32,"88":32,"89":32,"90":100,"91":101,"92":118,"93":105,"94":99,"95":101,"96":58,"97":32,"98":39,"99":47,"100":100,"101":101,"102":118,"103":47,"104":101,"105":116,"106":104,"107":49,"108":39,"109":10,"110":32,"111":32,"112":32,"113":32,"114":32,"115":125,"116":44,"117":10,"118":32,"119":32,"120":32,"121":32,"122":32,"123":111,"124":116,"125":97,"126":110,"127":101,"128":116,"129":119,"130":111,"131":114,"132":107,"133":58,"134":32,"135":123,"136":10,"137":32,"138":32,"139":32,"140":32,"141":32,"142":32,"143":32,"144":100,"145":101,"146":118,"147":105,"148":99,"149":101,"150":58,"151":32,"152":39,"153":47,"154":100,"155":101,"156":118,"157":47,"158":101,"159":116,"160":104,"161":48,"162":39,"163":10,"164":32,"165":32,"166":32,"167":32,"168":32,"169":125,"170":10,"171":32,"172":32,"173":32,"174":125,"175":10,"176":32,"177":125,"178":10,"179":125,"180":10,"181":10}

Code being used:

`
const fs = require('fs');

var flatten = require('flat');

var loadconfig = fs.readFileSync('config.json');

var config_params = flatten(loadconfig);

console.log("%j", config_params);

`

commented

I end up with the same output.

Check the encoding of your file is UTF-8 not UTF-16.

By the way, you can just require('config.json'), node can read json files natively.

I've decided to fork and republish as I get the feeling that this project is abandoned.

I've re-released as flatley. If your problem isn't fixed by my version - open an Issue there (ideally with a reproduction) and I'll do my best to fix it.

https://www.npmjs.com/package/flatley
https://www.github.com/antony/flatley

Enjoy!

As mentioned before please ensure your file is encoded in the UTF-8 format.