当前位置:网站首页>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进一步地发展。
边栏推荐
- Détails du contrôle de la congestion TCP | 3. Espace de conception
- [combinatorics] combinatorial identities (review of eight combinatorial identities | product of combinatorial identities 1 | proof | use scenario | general method for finding combinatorial numbers)
- "The NTP socket is in use, exiting" appears when ntpdate synchronizes the time
- 程序猿如何快速成长
- 8 tips for effective performance evaluation
- 0214-27100 a day with little fluctuation
- Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
- "Everyday Mathematics" serial 56: February 25
- Explore Cassandra's decentralized distributed architecture
- MongoDB 的安装和基本操作
猜你喜欢

Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
![[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display](/img/46/c7f566f8fd46d383b055582d680bb7.png)
[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display

Getting started with Message Oriented Middleware

Mixlab编辑团队招募队友啦~~

Initial test of scikit learn Library

IDEA-配置插件

QT串口ui设计和解决显示中文乱码

Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day

【LeetCode】94. Middle order traversal of binary tree
随机推荐
Qt插件之自定义插件构建和使用
如何在本机搭建SVN服务器
什么是质押池,如何进行质押呢?
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
Top k questions of interview
在ntpdate同步时间的时候出现“the NTP socket is in use, exiting”
Extraction of the same pointcut
Initial test of scikit learn Library
Threejs Part 2: vertex concept, geometry structure
TCP congestion control details | 3 design space
【剑指 Offer 】57 - II. 和为s的连续正数序列
Zebras are recognized as dogs, and Stanford found the reason why AI made mistakes
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
One article takes you to understand machine learning
[combinatorics] combinatorial identities (review of eight combinatorial identities | product of combinatorial identities 1 | proof | use scenario | general method for finding combinatorial numbers)
Register in PHP_ Globals parameter settings
切入点表达式
跟我学企业级flutter项目:简化框架demo参考
[combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
【LeetCode】94. Middle order traversal of binary tree