{"id":267334,"date":"2015-11-02T21:10:02","date_gmt":"2015-11-02T18:10:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=267334"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=267334","title":{"rendered":"JSON \u0434\u043b\u044f \u043b\u044e\u0431\u0438\u0442\u0435\u043b\u0435\u0439 \u0441\u043a\u043e\u0431\u043e\u0447\u0435\u043a"},"content":{"rendered":"<p>       \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u0442\u0435\u043c\u0443 \u00ab\u041d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 JSON\u00bb \u043c\u0435\u043d\u044f \u043f\u043e\u0441\u0435\u0442\u0438\u043b\u0430 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043c\u044b\u0441\u043b\u044c \u043e\u0431 \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 JSON \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0412 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"http:\/\/habrahabr.ru\/post\/269461\">\u00ab\u0423\u0441\u043b\u043e\u0436\u043d\u0451\u043d\u043d\u044b\u0439 \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 JSON\u00bb<\/a> \u044f \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 NSNJSON, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u0435 JSON \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0435\u0433\u043e 4 JSON \u0442\u0438\u043f\u043e\u0432: <i>number<\/i>, <i>string<\/i>, <i>array<\/i>, <i>object<\/i>.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u044e\u0431\u044b\u0445 JSON \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0435\u0433\u043e 3 \u0442\u0438\u043f\u043e\u0432: <i>number<\/i>, <i>string<\/i>, <i>array<\/i>.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/ffd\/828\/0ba\/ffd8280ba9f14f8b8b46d531b215f5c3.png\"\/><br \/>  <a name=\"habracut\"><\/a><\/p>\n<h3><b>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/b><\/h3>\n<p>  <a href=\"#history\">\u0418\u0441\u0442\u043e\u0440\u0438\u044f<\/a><br \/>  <a href=\"#project_brackets\">\u041f\u0440\u043e\u0435\u043a\u0442 \u00abBrackets\u00bb<\/a><br \/>  <a href=\"#implementation\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/a><br \/>  <a href=\"#examples\">\u041f\u0440\u0438\u043c\u0435\u0440\u0447\u0438\u043a\u0438<\/a><\/p>\n<p>  <a name=\"history\"><\/a>  <\/p>\n<h4><b>\u0418\u0441\u0442\u043e\u0440\u0438\u044f<\/b><\/h4>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 NSNJSON \u044f \u043d\u0430\u0447\u0430\u043b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 <a href=\"http:\/\/habrahabr.ru\/post\/269461\/#drivers\">\u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430\u043c\u0438<\/a> \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430. \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0443 \u043c\u0435\u043d\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0438\u0434\u0435\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\/\u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f JSON.<\/p>\n<p>  \u0412 \u0445\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u044d\u0442\u043e\u0439 \u0438\u0434\u0435\u0435\u0439 \u044f \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b\u2026 \u0418 \u0432\u043e\u0442 \u043e\u0434\u043d\u0430\u0436\u0434\u044b, \u043c\u0435\u043d\u044f \u0438 \u043f\u043e\u0441\u0435\u0442\u0438\u043b\u0430 \u044d\u0442\u043e \u0431\u0435\u0437\u0443\u043c\u043d\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u043f\u043e\u0434 \u043a\u043e\u0434\u043e\u0432\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <i>\u00abBrackets\u00bb<\/i>.<\/p>\n<p>  \u042f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 JSON \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u0440\u043e\u043a, \u0447\u0438\u0441\u0435\u043b \u0438 \u0441\u043a\u043e\u0431\u043e\u0447\u0435\u043a!<br \/>  <a name=\"project_brackets\"><\/a>  <\/p>\n<h4><b>\u041f\u0440\u043e\u0435\u043a\u0442 \u00abBrackets\u00bb<\/b><\/h4>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0432\u0435\u0434\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0434\u043b\u044f JSON \u0442\u0438\u043f\u043e\u0432.  <\/p>\n<table>\n<tr>\n<th>JSON \u0442\u0438\u043f<\/th>\n<th>number<\/th>\n<th>string<\/th>\n<th>true<\/th>\n<th>false<\/th>\n<th>array<\/th>\n<th>object<\/th>\n<\/tr>\n<tr>\n<td>\u041c\u0430\u0440\u043a\u0435\u0440<\/td>\n<td>1<\/td>\n<td>2<\/td>\n<td>3<\/td>\n<td>3<\/td>\n<td>4<\/td>\n<td>5<\/td>\n<\/tr>\n<\/table>\n<p>  \u0414\u043b\u044f \u0442\u0438\u043f\u0430 <i>null<\/i> \u0432\u0441\u0451 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e. \u041f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432.  <\/p>\n<pre><code class=\"javascript\">null -&gt; [] <\/code><\/pre>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <i>value<\/i> \u0442\u0438\u043f\u0430 <i>string<\/i>:  <\/p>\n<pre><code class=\"javascript\">value -&gt; [1, value] <\/code><\/pre>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <i>value<\/i> \u0442\u0438\u043f\u0430 <i>string<\/i>:  <\/p>\n<pre><code class=\"javascript\">value -&gt; [2, value] <\/code><\/pre>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <i>value<\/i> \u0442\u0438\u043f\u0430 <i>boolean<\/i> (<i>true<\/i>, <i>false<\/i>):  <\/p>\n<pre><code class=\"javascript\">value -&gt; [3, ~~value] \/\/ [3, 1] \u0434\u043b\u044f true \/\/ [3, 0] \u0434\u043b\u044f false <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u041d\u0430\u0447\u043d\u0443 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432. \u0414\u043b\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"javascript\">array -&gt; [4, p1, ..., pN] \/\/ p1, ..., pN - \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <\/code><\/pre>\n<p>  \u0421 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0432\u0435\u0434\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044f\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<br \/>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<br \/>  \u041f\u0443\u0441\u0442\u044c \u043f\u043e\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u043c\u0435\u0435\u0442 \u0438\u043c\u044f <i>name<\/i> \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <i>value<\/i>. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"javascript\">name: value -&gt; [name, valuePresentation] \/\/ valuePresentation - \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f value <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0446\u0435\u043b\u0438\u043a\u043e\u043c:  <\/p>\n<pre><code class=\"javascript\">name: value -&gt; [5, [name1, value1Presentation], ..., [nameN, valueNPresentation]] \/\/ value1Presentation, ..., valueNPresentation - \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 value1, ..., valueN <\/code><\/pre>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0432 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f JSON.<br \/>   \u2014 \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441 \u043f\u0443\u0441\u0442\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c, \u2014 \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <i>null<\/i>.<br \/>   \u2014 \u0418\u043d\u0430\u0447\u0435, \u0431\u0435\u0440\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438 \u0438\u0449\u0435\u043c \u043f\u043e \u043d\u0435\u043c\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0438\u043c\u044f JSON \u0442\u0438\u043f\u0430. \u0414\u0430\u043b\u0435\u0435, \u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043d\u0443\u0436\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  <a name=\"implementation\"><\/a>  <\/p>\n<h3><b>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/h3>\n<p>  \u042f \u043f\u043e\u043a\u0430\u0436\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/nsnjson\/nsnjson-nodejs-driver\">NSNJSON Node.js \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430<\/a>.<\/p>\n<p>  \u0414\u0440\u0430\u0439\u0432\u0435\u0440 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d \u043d\u0430 <a href=\"https:\/\/www.npmjs.com\">npmjs.com<\/a>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443:  <\/p>\n<pre><code class=\"bash\">npm install nsnjson-driver <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u044f \u043d\u0430\u0447\u043d\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0445\u043e\u0447\u0443 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <b><a href=\"https:\/\/github.com\/folktale\/data.maybe\/blob\/master\/lib\/maybe.js\">Maybe<\/a><\/b> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 <b><a href=\"https:\/\/www.npmjs.com\/package\/data.maybe\">data.maybe<\/a><\/b>.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0434\u0432\u0430 \u0444\u0430\u0439\u043b\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442.<\/p>\n<p>  \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u043c\u0430\u0440\u043a\u0435\u0440\u043e\u0432 (<i>custom.format.json<\/i>):  <\/p>\n<pre><code class=\"javascript\">{   &quot;TYPE_MARKER_NUMBER&quot;:  1,   &quot;TYPE_MARKER_STRING&quot;:  2,   &quot;TYPE_MARKER_BOOLEAN&quot;: 3,   &quot;TYPE_MARKER_ARRAY&quot;:   4,   &quot;TYPE_MARKER_OBJECT&quot;:  5 } <\/code><\/pre>\n<p>  \u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0438\u043c\u0435\u043d JSON \u0442\u0438\u043f\u043e\u0432 (<i>nsnjson.types.json<\/i>):  <\/p>\n<pre><code class=\"javascript\">{   &quot;NULL&quot;:    &quot;null&quot;,   &quot;NUMBER&quot;:  &quot;number&quot;,   &quot;STRING&quot;:  &quot;string&quot;,   &quot;BOOLEAN&quot;: &quot;boolean&quot;,   &quot;ARRAY&quot;:   &quot;array&quot;,   &quot;OBJECT&quot;:  &quot;object&quot; } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\/\u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f JSON.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">custom.encoder.js<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">var Maybe = require('data.maybe');  var nsnjson = require('nsnjson-driver');  var Types = require('.\/nsnjson.types');  var Format = require('.\/custom.format');  var encodingOptions = {};  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f value \u0442\u0438\u043f\u0430 JSON null encodingOptions[Types.NULL] = function() {   return Maybe.Just([]); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f value \u0442\u0438\u043f\u0430 JSON number encodingOptions[Types.NUMBER] = function(value) {   return Maybe.Just([Format.TYPE_MARKER_NUMBER, value]); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f value \u0442\u0438\u043f\u0430 JSON string encodingOptions[Types.STRING] = function(value) {   return Maybe.Just([Format.TYPE_MARKER_STRING, value]); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f value \u0442\u0438\u043f\u0430 JSON boolean encodingOptions[Types.BOOLEAN] = function(value) {   return Maybe.Just([Format.TYPE_MARKER_BOOLEAN, ~~value]); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f array \u0442\u0438\u043f\u0430 JSON array encodingOptions[Types.ARRAY] = function(array) {   var presentation = [Format.TYPE_MARKER_ARRAY];    for (var i = 0, size = array.length; i &lt; size; i++) {     var itemPresentationMaybe = this.encode(array[i]);      if (itemPresentationMaybe.isJust) {       var itemPresentation = itemPresentationMaybe.get();        presentation.push(itemPresentation);     }   }    return Maybe.Just(presentation); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f object \u0442\u0438\u043f\u0430 JSON object encodingOptions[Types.OBJECT] = function(object) {   var presentation = [Format.TYPE_MARKER_OBJECT];    for (var name in object) {     if (object.hasOwnProperty(name)) {       var valuePresentationMaybe = this.encode(object[name]);        if (valuePresentationMaybe.isJust) {         var valuePresentation = valuePresentationMaybe.get();          var fieldPresentation = [name, valuePresentation];          presentation.push(fieldPresentation);       }     }   }    return Maybe.Just(presentation); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">custom.decoder.js<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">var Maybe = require('data.maybe');  var nsnjson = require('nsnjson-driver');  var Types = require('.\/nsnjson.types');  var Format = require('.\/custom.format')  var decodingOptions = {   \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u043d\u0438 JSON \u0442\u0438\u043f\u0430 \u0438\u0437 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f.   'type': function(presentation) {     if (presentation.length == 0) {       return Maybe.Just(Types.NULL);     } else {       switch (presentation[0]) {         case Format.TYPE_MARKER_NUMBER:  return Maybe.Just(Types.NUMBER);         case Format.TYPE_MARKER_STRING:  return Maybe.Just(Types.STRING);         case Format.TYPE_MARKER_BOOLEAN: return Maybe.Just(Types.BOOLEAN);         case Format.TYPE_MARKER_ARRAY:   return Maybe.Just(Types.ARRAY);         case Format.TYPE_MARKER_OBJECT:  return Maybe.Just(Types.OBJECT);       }        return Maybe.Nothing();     }   } };  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 JSON null decodingOptions[Types.NULL] = function() {   return Maybe.Just(null); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 JSON number decodingOptions[Types.NUMBER] = function(presentation) {   return Maybe.Just(presentation[1]); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 JSON string decodingOptions[Types.STRING] = function(presentation) {   return Maybe.Just(presentation[1]); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 JSON boolean decodingOptions[Types.BOOLEAN] = function(presentation) {   return Maybe.Just(presentation[1] != 0); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 JSON array decodingOptions[Types.ARRAY] = function(presentation) {   var array = [];    for (var i = 1, size = presentation.length; i &lt; size; i++) {     var itemPresentation = presentation[i];      var itemMaybe = this.decode(itemPresentation);      if (itemMaybe.isJust) {       var item = itemMaybe.get();        array.push(item);     }   }    return Maybe.Just(array); }  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 JSON object decodingOptions[Types.OBJECT] = function(presentation) {   var object = {};    for (var i = 1, size = presentation.length; i &lt; size; i++) {     var fieldPresentation = presentation[i];      var name = fieldPresentation[0];      var valueMaybe = this.decode(fieldPresentation[1]);      if (valueMaybe.isJust) {       var value = valueMaybe.get();        object[name] = value;     }   }    return Maybe.Just(object); }  module.exports = {   decode: function(presentation) {     return nsnjson.decode(presentation, decodingOptions);   } }; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0443 \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f.  <\/p>\n<pre><code class=\"javascript\">\/\/ \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c encoder \u0441 \u043d\u0430\u0448\u0438\u043c\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f JSON var customEncoder = require('.\/custom.encoder');  \/\/ \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c decoder \u0441 \u043d\u0430\u0448\u0438\u043c\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f JSON var customDecoder = require('.\/custom.decoder');  var data = {message: ['I', 'love', 'brackets']};  console.log('Data:', JSON.stringify(data)); \/\/ Data: { &quot;message&quot;: [ &quot;I&quot;, &quot;love&quot;, &quot;brackets&quot; ] }  var presentationMaybe = customEncoder.encode(data);  if (presentationMaybe.isJust) {     var presentation = presentationMaybe.get();      console.log('Presentation:', JSON.stringify(presentation));     \/\/ Presentation: [ 5, [ &quot;message&quot;, [ 4, [ 2, &quot;I&quot; ], [ 2, &quot;love&quot; ], [ 2, &quot;brackets&quot; ] ] ] ]      var restoredDataMaybe = customDecoder.decode(presentation);      if (restoredDataMaybe.isJust) {         var restoredData = restoredDataMaybe.get();          console.log('Restored data:', JSON.stringify(restoredData));         \/\/ Restored data: { &quot;message&quot;: [ &quot;I&quot;, &quot;love&quot;, &quot;brackets&quot; ] }     } } <\/code><\/pre>\n<p>  <a name=\"examples\"><\/a>  <\/p>\n<h4><b>\u041f\u0440\u0438\u043c\u0435\u0440\u0447\u0438\u043a\u0438<\/b><\/h4>\n<p>  \u041f\u043e \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0438, \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0447\u0438\u043a\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f JSON \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0447\u0438\u043a\u0438<\/b><\/p>\n<div class=\"spoiler_text\"><b>JSON \u0442\u0438\u043f <i>null<\/i><\/b>  <\/p>\n<pre><code class=\"javascript\">\/\/ JSON null  \/\/ NSNJSON [ ] <\/code><\/pre>\n<p>  <b>JSON \u0442\u0438\u043f <i>number<\/i><\/b>  <\/p>\n<pre><code class=\"javascript\">\/\/ JSON 2015  \/\/ NSNJSON [ 1, 2015 ] <\/code><\/pre>\n<p>  <b>JSON \u0442\u0438\u043f <i>boolean<\/i><\/b>  <\/p>\n<pre><code class=\"javascript\">\/\/ JSON true  \/\/ NSNJSON [ 3, 1 ] <\/code><\/pre>\n<p>  <b>JSON \u0442\u0438\u043f <i>string<\/i><\/b>  <\/p>\n<pre><code class=\"javascript\">\/\/ JSON &quot;Habrahabr.ru&quot;  \/\/ NSNJSON [ 2, &quot;Habrahabr.ru&quot; ] <\/code><\/pre>\n<p>  <b>JSON \u0442\u0438\u043f <i>array<\/i><\/b>  <\/p>\n<pre><code class=\"javascript\">\/\/ JSON [ &quot;Year&quot;, 2015 ]  \/\/ NSNJSON [ 4, [ 2, &quot;Year&quot; ], [ 1, 2015 ] ] <\/code><\/pre>\n<p>  <b>JSON \u0442\u0438\u043f <i>object<\/i><\/b>  <\/p>\n<pre><code class=\"javascript\">\/\/ JSON { &quot;message&quot;: [ &quot;I&quot;, &quot;love&quot;, &quot;brackets&quot; ] }  \/\/ NSNJSON [ 5, [ &quot;message&quot;, [ 4, [ 2, &quot;I&quot; ], [ 2, &quot;love&quot; ], [ 2, &quot;brackets&quot; ] ] ] ] <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0443 \u0432\u043e\u0442 \u0438 \u043f\u043e\u0434\u043e\u0448\u043b\u0430 \u043a \u043a\u043e\u043d\u0446\u0443 \u0441\u0442\u0430\u0442\u044c\u044f \u043e \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, JSON \u0438 \u0441\u043a\u043e\u0431\u043e\u0447\u043a\u0430\u0445. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0412\u0430\u0448\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/269993\/\"> http:\/\/habrahabr.ru\/post\/269993\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u0442\u0435\u043c\u0443 \u00ab\u041d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 JSON\u00bb \u043c\u0435\u043d\u044f \u043f\u043e\u0441\u0435\u0442\u0438\u043b\u0430 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043c\u044b\u0441\u043b\u044c \u043e\u0431 \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 JSON \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0412 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"http:\/\/habrahabr.ru\/post\/269461\">\u00ab\u0423\u0441\u043b\u043e\u0436\u043d\u0451\u043d\u043d\u044b\u0439 \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 JSON\u00bb<\/a> \u044f \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 NSNJSON, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u044b\u0435 JSON \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0435\u0433\u043e 4 JSON \u0442\u0438\u043f\u043e\u0432: <i>number<\/i>, <i>string<\/i>, <i>array<\/i>, <i>object<\/i>.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u044e\u0431\u044b\u0445 JSON \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0435\u0433\u043e 3 \u0442\u0438\u043f\u043e\u0432: <i>number<\/i>, <i>string<\/i>, <i>array<\/i>.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/ffd\/828\/0ba\/ffd8280ba9f14f8b8b46d531b215f5c3.png\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-267334","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=267334"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267334\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=267334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=267334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=267334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}