当前位置:网站首页>JSON 与 BSON 区别
JSON 与 BSON 区别
2022-07-03 16:32:00 【云闲不收】
BSON
BSON是由10gen开发的一个数据格式,目前主要用于MongoDB中,是MongoDB的数据存储格式。BSON基于JSON格式,选择JSON进行改造的原因主要是JSON的通用性及JSON的schemaless的特性。
按照定义性来说:
BSON( Binary Serialized Document Format) 是一种二进制形式的存储格式,采用了类似于 C 语言结构体的名称、对表示方法,支持内嵌的文档对象和数组对象,具有轻量性、可遍历性、高效性的特点,可以有效描述非结构化数据和结构化数据。
BSON是一种类JSON的一种二进制形式的存储格式,简称Binary JSON,它和JSON一样,支持内嵌的文档对象和数组对象,但是BSON有JSON没有的一些数据类型,如Date和BinData类型。
BSON可以做为网络数据交换的一种存储形式,这个有点类似于Google的Protocol Buffer,但是BSON是一种schema-less的存储形式,它的优点是灵活性高,但它的缺点是空间利用率不是很理想.
总的来说:
BSON有三个特点:轻量性、可遍历性、高效性。
JSON
JSON是 JavaScript Object Notation 的首字母缩写,单词的意思是javascript对象表示法,这里说的json指的是类似于javascript对象的一种数据格式。
使用JSON的格式与解析方便的可以表示一个对象信息,json有两种格式:①对象格式:{“key1”:obj,“key2”:obj,“key3”:obj…}、②数组/集合格式:[obj,obj,obj…]。
1.更快的遍历速度
对json格式来说,太大的json结构会导致数据遍历非常慢。在json中,要跳过一个文档进行数据读取,需要对此文档进行扫描才行,需要进行麻烦的数据结构匹配,比如括号的匹配。
而BSON对json的一大改进就是,它会将json的每一个元素的长度存在元素的头部,这样你只需要读取到元素长度就能直接seek到指定的点上进行读取了。
2.操作更简易
对JSON来说,数据存储是无类型的,比如你要修改基本一个值,从9到10,由于从一个字符变成了两个,所以可能其后面的所有内容都需要往后移一位才可以。
而使用BSON,你可以指定这个列为数字列,那么无论数字从9长到10还是100,我们都只是在存储数字的那一位上进行修改,不会导致数据总长变大。
当然,在mongoDB中,如果数字从整形增大到长整型,还是会导致数据总长变大的。
3.增加了额外的数据类型
JSON是一个很方便的数据交换格式,但是其类型比较有限。
BSON在其基础上增加了“byte array”数据类型。这使得二进制的存储不再需要先base64转换后再存成JSON,大大减少了计算开销和数据大小。
当然,在有的时候,BSON相对JSON来说也并没有空间上的优势,比如对{“field”:7},在JSON的存储上7只使用了一个字节,而如果用BSON,那就是至少4个字节(32位)
目前在10gen的努力下,BSON已经有了针对多种语言的编码解码包。并且都是Apache 2 license下开源的。并且还在随着mongoDB进一步地发展。
边栏推荐
- Expression of request header in different countries and languages
- IDEA-配置插件
- 8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
- Advanced Mathematics (Seventh Edition) Tongji University exercises 2-1 personal solutions
- MySQL converts comma separated attribute field data from column to row
- Eleven requirements for test management post
- Interviewer: how does the JVM allocate and recycle off heap memory
- NSQ源码安装运行过程
- Pointcut expression
- Nine ways to define methods in scala- Nine ways to define a method in Scala?
猜你喜欢
Thread pool executes scheduled tasks
Mysql 将逗号隔开的属性字段数据由列转行
Unreal_DataTable 实现Id自增与设置RowName
arduino-esp32:LVGL项目(一)整体框架
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
Getting started with Message Oriented Middleware
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
Interviewer: how does the JVM allocate and recycle off heap memory
There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
随机推荐
Qt插件之自定义插件构建和使用
Golang 匿名函数使用
SVN使用规范
Record windows10 installation tensorflow-gpu2.4.0
Basis of target detection (IOU)
[combinatorics] combinatorial identity (sum of combinatorial identity products 1 | sum of products 1 proof | sum of combinatorial identity products 2 | sum of products 2 proof)
[statement] about searching sogk1997 and finding many web crawler results
Unreal_DataTable 实现Id自增与设置RowName
Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day
Threejs Part 2: vertex concept, geometry structure
Cocos Creator 2. X automatic packaging (build + compile)
One article takes you to understand machine learning
MySQL converts comma separated attribute field data from column to row
Acwing game 58
跟我学企业级flutter项目:简化框架demo参考
Pointcut expression
Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
探索Cassandra的去中心化分布式架构
[solved] access denied for user 'root' @ 'localhost' (using password: yes)
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug