CSON vs JSON
CSON vs JSON
今天在github浏览资料时,无意发现了这个很像json,却优于json的cson.故,再次分享给大家!
官方fork文档:https://github.com/xgqfrms/cson
What is CSON?
CoffeeScript-Object-Notation. Same as JSON but for CoffeeScript objects.
cosn有比json更宽松,更好的读写方式,并且不需要引号,摆脱一切,它拥有注释和可读的多行字符串,即使你忘了一个逗号,也不会出错!
对比:
json的格式:
{
"greatDocumentaries": [
"earthlings.com",
"forksoverknives.com",
"cowspiracy.com"
],
"importantFacts": {
"emissions": "Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.\nGoodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”\nWorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.\nhttp://www.worldwatch.org/node/6294",
"landuse": "Livestock covers 45% of the earth’s total land.\nThornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).\nhttps://cgspace.cgiar.org/bitstream/handle/10568/10601/IssueBrief3.pdf",
"burger": "One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.\nCatanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.\nhttp://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/\n“50 Ways to Save Your River.” Friends of the River.\nhttp://www.friendsoftheriver.org/site/PageServer?pagename=50ways",
"milk": "1,000 gallons of water are required to produce 1 gallon of milk.\n“Water trivia facts.” United States Environmental Protection Agency.\nhttp://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11",
"more": "http://cowspiracy.com/facts"
}
}
cson的格式:
# Comments!!! # An Array with no commas!
greatDocumentaries: [
'earthlings.com'
'forksoverknives.com'
'cowspiracy.com'
] # An Object without braces!
importantFacts:
# Multi-Line Strings! Without Quote Escaping!
emissions: '''
Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
Goodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”
WorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.
http://www.worldwatch.org/node/6294
''' landuse: '''
Livestock covers 45% of the earth’s total land.
Thornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).
https://cgspace.cgiar.org/bitstream/handle/10568/10601/IssueBrief3.pdf
''' burger: '''
One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.
Catanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.
http://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/
“50 Ways to Save Your River.” Friends of the River.
http://www.friendsoftheriver.org/site/PageServer?pagename=50ways
''' milk: '''
1,000 gallons of water are required to produce 1 gallon of milk.
“Water trivia facts.” United States Environmental Protection Agency.
http://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11
''' more: 'http://cowspiracy.com/facts'
NPM 安装方法:
- Use:
require('cson')
- Install:
npm install --save cson
使用 CSON 的方式:
1. 命令行方式:
# Convert a JSON file into a CSON file
json2cson in.json > out.cson
# Same thing via piping
cat in.json | json2cson > out.cson # Convert a CSON file into a JSON file
cson2json in.cson > out.json
# Same thing via piping
cat in.cson | cson2json > out.json
需要一个全局的 CSON 安装包: npm install -g cson
2. 通过 API 方式:
每一个方法都能被执行 ,使用像这样的一个回调:
result = require('CSON').createCSONString({a:{b:'c'}}, {/* optional options argument */})
if ( result instanceof Error ) {
console.log(result.stack)
} else {
console.log(result)
}
或 通过像这样的一个回调:
CSON.createCSONString({a:{b:'c'}}, {/* optional options argument */}, function(err,result){
console.log(err, result)
})
创建字符串:
String CSON.stringify(data, replacer?, indent?)
Converts an Object into a CSON StringString CSON.createCSONString(data, opts?, next?)
Converts an Object into a CSON StringString CSON.createJSONString(data, opts?, next?)
Converts an Object into a JSON StringString CSON.createString(data, opts?, next?)
Converts an Object into a String of the desired format If the format option is not specified, we default to CSON
解析字符串:
Object CSON.parse(data, opts?, next?)
Parses a CSON String into an ObjectObject CSON.parseCSONString(data, opts?, next?)
Parses a CSON String into an ObjectObject CSON.parseJSONString(data, opts?, next?)
Parses a JSON String into an ObjectObject CSON.parseCSString(data, opts?, next?)
Parses a CoffeeScript String into an ObjectObject CSON.parseJSString(data, opts?, next?)
Parses a JavaScript String into an ObjectObject CSON.parseString(data, opts?, next?)
Converts a String of the desired format into an Object If the format option is not specified, we default to CSON
需求文件:
Object CSON.requireCSFile(filePath, opts?, next?)
Requires a CoffeeScript file and returns the result ObjectObject CSON.requireJSFile(filePath, opts?, next?)
Requires a JavaScript file and returns the result ObjectObject CSON.requireFile(filePath, opts?, next?)
Requires or parses a file path of the desired format into an Object If the format option is not specified, we use the filename to detect what it should be, otherwise we default to parsing CSON
许可授权:
Unless stated otherwise all works are:
- Copyright 2012+ Bevry Pty Ltd us@bevry.me (http://bevry.me)
- Copyright 2011 Benjamin Lupton b@lupton.cc (http://balupton.com)
and licensed under:
- The incredibly permissive MIT License
CSON vs JSON的更多相关文章
- Confman - 针对「Node 应用」的配置文件加载模块
一句话介绍 confman 是一个强大的配置文件加载器,无论你喜欢 yaml .cson.json.properties.plist.ini.toml.xml 还是 js,都能满足你的愿望,并且更加简 ...
- 使用TSQL查询和更新 JSON 数据
JSON是一个非常流行的,用于数据交换的文本数据(textual data)格式,主要用于Web和移动应用程序中.JSON 使用“键/值对”(Key:Value pair)存储数据,能够表示嵌套键值对 ...
- 【疯狂造轮子-iOS】JSON转Model系列之二
[疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...
- 【疯狂造轮子-iOS】JSON转Model系列之一
[疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...
- Taurus.MVC 2.2 开源发布:WebAPI 功能增强(请求跨域及Json转换)
背景: 1:有用户反馈了关于跨域请求的问题. 2:有用户反馈了参数获取的问题. 3:JsonHelper的增强. 在综合上面的条件下,有了2.2版本的更新,也因此写了此文. 开源地址: https:/ ...
- .NET Core系列 : 2 、project.json 这葫芦里卖的什么药
.NET Core系列 : 1..NET Core 环境搭建和命令行CLI入门 介绍了.NET Core环境,本文介绍.NET Core中最重要的一个配置文件project.json的相关内容.我们可 ...
- 一个粗心的Bug,JSON格式不规范导致AJAX错误
一.事件回放 今天工作时碰到了一个奇怪的问题,这个问题很早很早以前也碰到过,不过没想到过这么久了竟然又栽在这里. 当时正在联调一个项目,由于后端没有提供数据接口,于是我直接本地建立了一个 json ...
- JSON.parse()和JSON.stringify()
1.parse 用于从一个字符串中解析出json 对象.例如 var str='{"name":"cpf","age":"23&q ...
- json与JavaScript对象互换
1,json字符串转化为JavaScript对象: 方法:JSON.parse(string) eg:var account = '{"name":"jaytan&quo ...
随机推荐
- uni-app开发经验分享二: uni-app生命周期记录
应用生命周期(仅可在App.vue中监听) 页面生命周期(在页面中添加) 当页面中需要用到下拉刷新功能时,打开pages.json,在"globalStyle"里设置"e ...
- 【JeecgBoot】关于 jeecg-boot 的项目理解、使用心得和改进建议
工欲善其事,必先利其器. 脚手架选型 一年前,我接到为团队落地一个快速开发脚手架的任务. 在月底这节骨眼上,时间紧,任务急,有想自己撸一个脚手架的人都赶紧把这想法收起来吧!这劳民又伤身的事咱肯定是不能 ...
- Devexpress DockManager多页面浮动窗口会关闭所有页面的问题
注册 DockManager 的 ClosingPanel 事件 private void DockManager1_ClosingPanel(object sender, DockPanelCanc ...
- Netty之ChannelHandler
一.概述 handler是控制socket io的各个生命周期的业务实现,netty实现了很多种协议所以有很多handler类,这儿主要关注Handler的设计.作用以及使用方法. 二.Channel ...
- Mybatis总结(一)
Mybatis总结(一) 一.Mybatis启动流程(代码层面) 关于config.xml <?xml version="1.0" encoding="UTF-8& ...
- 数据水印 watermark
外发数据创建水印 产品通过对外发数据进行添加数据标记.自动生成水印.数据源追溯等功能,避免了内部人员外发数据泄露无法对事件追溯,提高了数据传递的安全性和可追溯能力. 数据水印系统_数据安全管理工具_[ ...
- Makefile 描述的是文件编译的相关规则,它的规则主要是两个部分组成,分别是依赖的关系和执行的命令 PHONY伪目标实践
Makefile的工作流程 http://c.biancheng.net/view/7091.html Makefile文件是什么? 我们教程主要是讲的是 Makefile .很多 Linux(Uni ...
- memory ordering 内存排序
Memory ordering - Wikipedia https://en.wikipedia.org/wiki/Memory_ordering https://zh.wikipedia.org/w ...
- MySQL 高性能优化规范建议
数据库命令规范 所有数据库对象名称必须使用小写字母并用下划线分割 所有数据库对象名称禁止使用 MySQL 保留关键字(如果表名中包含关键字查询时,需要将其用单引号括起来) 数据库对象的命名要能做到见名 ...
- LOJ10075 农场派对
USACO 2007 Feb. Silver N(1≤N≤1000) 头牛要去参加一场在编号为 x(1≤x≤N) 的牛的农场举行的派对.有 M(1≤M≤100000) 条有向道路,每条路长Ti(1≤ ...