Coder Social home page Coder Social logo

ej's Introduction

ej

ej = export json to csv

npm version

原因

我们使用mongodb会经常导出json

mongoexport -d xbm-wechat-api -c senddeliveryhistories -o senddeliveryhistories.json  --jsonArray --query "{date:{\$in:['20150821','20150822']}}"

但json转成csv又没有上面的header,如果使用json2csv这样库,又无法解决对象嵌套的取值问题,所以就写了ej这个工具,它可以直接把mongoexport导出的json直接转成csv

比如

[
  {
    "__v": 0,
    "_id": {
      "$oid": "55bf208846b246fa238ff4d7"
    },
    "created_at": {
      "$date": "2015-08-03T08:04:24.648Z"
    },
    "date": "20150803",
  }
]

会生成以下4列

  • __v
  • _id.$oid
  • created_at.$date
  • date

Install

[sudo] npm install -g ej

Usages

ej input.json output.csv

Code

var ej  = require('ej');

var s = root + "/senddeliveryhistories.json";
var d = root + '/' + req.query.date + '-' + time + ".csv";
ej(s.replace('//','/'),d.replace('//','/'),function(){
  // success
},function(){
  // fail
});

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

版本历史

  • v1.0.4 增加成功和失败callback
  • v1.0.0 初始化版本,实现ej导出

欢迎fork和反馈

如有建议或意见,请在issue提问或邮件

License

this repo is released under the MIT License.

ej's People

Contributors

i5ting avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.