nullnullnunlnununnuulll

JSON.stringify(value,null,4)

nil JSON JOSN JSOSH

json_encode(array(
    "data_source" => DATA_SOURCE, "description" => DESCRIPTION,
  ), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
[ ]
 

npm install -g git+https://git@github.com/aseemk/json5.git

Use JSON5. Don't use JSON.

Objects and arrays can have trailing commas
Object keys can be unquoted if they're valid identifiers
Strings can be single-quoted
Strings can be split across multiple lines
Numbers can be hexadecimal (base 16)
Numbers can begin or end with a (leading or trailing) decimal point.
Numbers can include Infinity and -Infinity.
Numbers can begin with an explicit plus (+) sign.
Both inline (single-line) and block (multi-line) comments are allowed.

http://json5.org/
https://github.com/aseemk/json5

[ ]
 

Наиболее перспективен, на мой взгляд, JSONSelect поскольку всё остальное мало понятная неудобная хрень. Но json:select() ешё не доделан до конца, там не так много фич, поэтому мы будем страдать.

json:select() http://jsonselect.org/#tryit

 ".author .drinkPref :first-child"

{
  "author": {
    "name": {
      "first": "Lloyd",
      "last": "Hilaiel"
    },
    "drinkPref": [
      "whiskey",
      "beer",
      "wine"
    ],
  },
  "thing": "JSONSelect site",
  "license": "(cc) BY-SA"
}

Result: "whiskey"

JSONSelect = require("JSONSelect")
JSONSelect.forEach(".points_to_delete .id",args,function(){
    result.push(arguments)
})

jsel https://github.com/dragonworx/jsel

dom.select('count(//*)') === 5;
dom.select('@title') === 'abc';
dom.select('//children/*[1]/@foo') === 'bar';
dom.select('count(//@foo)') === 2;
dom.select('//@foo[2]') === 555;
dom.select('count(//children//*)') === 2;
dom.select('//children/*[2]') === 'val';
dom.select('name(//children/*[2])') === 'string';
dom.select('name(*/*[2])') === 'subData';
dom.select('*/children/*[2]/text()') === 'val';
dom.selectAll('//@foo') === ['bar', 555];

JSPath https://github.com/dfilatov/jspath

 Quick example

JSPath.apply(
    '.automobiles{.maker === "Honda" && .year > 2009}.model',
    {
        "automobiles" : [
            { "maker" : "Nissan", "model" : "Teana", "year" : 2011 },
            { "maker" : "Honda", "model" : "Jazz", "year" : 2010 },
            { "maker" : "Honda", "model" : "Civic", "year" : 2007 },
            { "maker" : "Toyota", "model" : "Yaris", "year" : 2008 },
            { "maker" : "Honda", "model" : "Accord", "year" : 2011 }
        ],
        "motorcycles" : [{ "maker" : "Honda", "model" : "ST1300", "year" : 2012 }]
    });

Result will be:

['Jazz', 'Accord']

JsonPath http://goessner.net/articles/JsonPath/

$['store']['book'][0]['title']
$.store.book[*].author
$..author
$.store.*
$.store..price
$..book[2]
$..book[(@.length-1)]
$..book[-1:]
$..book[0,1]
$..book[:2]
$..book[?(@.isbn)]
$..book[?(@.price<10)]
$..* 

jLinq http://hugoware.net/Projects/jLinq

//select records
jlinq.from(data.source)
  .starts('first', 'a')
  .select();
 
//complex queries - no need to repeat names
//when querying the same field
jlinq.from(data.source)
    .starts('first', 'a')
    .or('b')
    .or('c')
    .sort('last')
    .select();
 
//sorting - multiple field
jlinq.from(data.source)
  .greater('age', 40)
  .sort('age', 'name');
  .select();
[ ]
 

Нашел функциию в интернете и слегка доработал её под свой стиль.

<?php

/**
 * Indents a flat JSON string to make it more human-readable.
 *
 * @param string $json The original JSON string to process.
 *
 * @return string Indented version of the original JSON string.
 */
function json_indent($json, $indentStr = "    ", $newLine = "n") 
{

  $ind       = 0; // Current indention width
  $result    = ""; // Resulting string
  $indention = ""; // Current indention after newline
  $escaped   = false; // FALSE or escape character
  $strLen    = strlen($json);

  for($i = 0; $i < $strLen; $i++) 
  {
    // Grab the next character in the string
    $char = $json[$i];

    if($escaped) 
    {

      if($escaped == $char)
      {
        // End of escaped sequence
        $escaped = false;
      }

      $result .= $char;
      if ($char == "\\" && $i + 1 < $strLen) 
      {
        // Next character will NOT end this sequence
        $result .= $json[++$i];
      }

      continue;
    }

    if ($char == '"' || $char == "'") 
    {
      // Escape this string
      $escaped = $char;
      $result .= $char;
      continue;
    }

    if(($char == '{' || $char == '[') ) 
    {
      $indention = str_repeat($indentStr, $ind++);
      if($i > 0 && $json[$i-1] != "," && $json[$i-1] != "[" && $json[$i-1] != "{")
      {
        $result .= $newLine . $indention;
      }
    }
    // If this character is the end of an element,
    // output a new line and indent the next line
    if ($char == '}' || $char == ']') 
    {
      $indention = str_repeat($indentStr, --$ind);
      $result .= $newLine . $indention;
    }

    // Add the character to the result string
    if($char == ":")
    {
      $result .= " $char ";
    }
    else
    {
      $result .= $char;
    }

    // If the last character was the beginning of an element,
    // output a new line and indent the next line
    if ($char == ',' || $char == '{' || $char == '[') 
    {
      if ($char == '{' || $char == '[') 
      {
        $indention = str_repeat($indentStr, $ind);
      }
      $result .= $newLine . $indention;
    }

  }

  return $result;
}

Печатает примерно такое:

{
    "fileCount" : 2,
    "data" : 
    [
        {
            "id" : "file.1",
            "class" : "file",
            "file" : "example_file.1.html",
            "display" : "example_file.1",
            "extension" : "html",
            "size" : 12345,
            "hasVersions" : true,
            "versions" : 
            {
                "fileCount" : 1,
                "data" : 
                [
                    {
                        "id" : "file.1.1",
                        "class" : "file",
                        "file" : "example_file.1.1.html",
                        "display" : "example_file.1.1",
                        "extension" : "html",
                        "size" : 12345,
                        "hasVersions" : false,
                        "versions" : null
                    }
                ]
            }
        },
        {
            "id" : "file.2",
            "class" : "file",
            "file" : "example_file.2.html",
            "display" : "example_file.2",
            "extension" : "html",
            "size" : 12345,
            "hasVersions" : false,
            "versions" : null
        }
    ]
}