// Parse a JSON string
// --------------------------------------------------------------------------------
// @param $json: JSON string to parse
// --------------------------------------------------------------------------------
// @throw "Input string may not be null"
// --------------------------------------------------------------------------------
// @return [literal|false]

@function json-decode($json) {
  $length: str-length($json);
  $pointer: 1;
  $value: null;

  @if $json == null {
    @return _throw("Input string may not be null.", $pointer);
  }

  @while $value !=
    false
    // Stop if error
    and
    $pointer <=
    $length
  {
    $read: _json-decode--value($json, $pointer);
    $pointer: nth($read, 1);
    $value: nth($read, 2);
  }

  @return $value;
}
