peterschussheim
10/11/2016 - 7:32 PM

json-parse

json-parse

[
  {
    "_id": "57fd403ef16b9947e4e86c4a",
    "index": 0,
    "guid": "a23ec1b9-1534-4077-ae6a-b97c8c4cb1ff",
    "isActive": true,
    "balance": "$3,948.49",
    "picture": "http://placehold.it/32x32",
    "age": 25,
    "eyeColor": "blue",
    "name": {
      "first": "Maricela",
      "last": "Lynn"
    },
    "company": "XIIX",
    "email": "maricela.lynn@xiix.org",
    "phone": "+1 (848) 446-2577",
    "address": "557 Randolph Street, Blodgett, Connecticut, 2971",
    "about": "Excepteur fugiat nulla reprehenderit cillum eiusmod culpa fugiat nostrud. Tempor aliquip tempor ipsum consequat adipisicing. Do laborum officia incididunt occaecat ipsum proident ex do nisi duis pariatur ex aliquip sunt. Adipisicing ipsum exercitation occaecat velit laboris commodo. Duis aliquip aliqua laborum id minim officia laborum consectetur.",
    "registered": "Wednesday, February 12, 2014 2:12 AM",
    "latitude": "69.132835",
    "longitude": "2.855043",
    "tags": [
      "exercitation",
      "tempor",
      "esse",
      "incididunt",
      "in"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Savannah Fields"
      },
      {
        "id": 1,
        "name": "Cochran Hudson"
      },
      {
        "id": 2,
        "name": "Roberta Davenport"
      }
    ],
    "greeting": "Hello, Maricela! You have 6 unread messages.",
    "favoriteFruit": "apple"
  },
  {
    "_id": "57fd403e6cce2b699f6847d7",
    "index": 1,
    "guid": "2b135a59-c4ad-468f-ba3b-41ae8f8478f9",
    "isActive": false,
    "balance": "$3,376.35",
    "picture": "http://placehold.it/32x32",
    "age": 27,
    "eyeColor": "green",
    "name": {
      "first": "Mays",
      "last": "Bush"
    },
    "company": "EARTHPURE",
    "email": "mays.bush@earthpure.biz",
    "phone": "+1 (810) 417-3904",
    "address": "592 Troy Avenue, Robinette, American Samoa, 4041",
    "about": "Ex labore ea anim excepteur mollit laborum mollit veniam reprehenderit exercitation. Cupidatat enim dolore est pariatur cupidatat irure. Ex dolor eu ea minim est eu amet incididunt. Nisi sunt aliquip sint cupidatat nostrud cillum tempor cillum sunt sunt deserunt. Amet laborum deserunt culpa deserunt labore duis velit culpa qui ad dolor magna ex ea. Qui cillum labore quis veniam nisi consectetur adipisicing commodo cillum consectetur. Lorem fugiat nostrud consequat consequat dolor veniam qui.",
    "registered": "Saturday, June 11, 2016 9:35 PM",
    "latitude": "48.655085",
    "longitude": "119.178036",
    "tags": [
      "proident",
      "Lorem",
      "ea",
      "ex",
      "voluptate"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Alford Sherman"
      },
      {
        "id": 1,
        "name": "Sellers Lindsey"
      },
      {
        "id": 2,
        "name": "Alisha Banks"
      }
    ],
    "greeting": "Hello, Mays! You have 10 unread messages.",
    "favoriteFruit": "strawberry"
  },
  {
    "_id": "57fd403e7e000dce131c30f1",
    "index": 2,
    "guid": "0d0cc917-e88a-412f-8427-acc9aae68d0e",
    "isActive": true,
    "balance": "$3,917.96",
    "picture": "http://placehold.it/32x32",
    "age": 27,
    "eyeColor": "brown",
    "name": {
      "first": "Bobbie",
      "last": "Howell"
    },
    "company": "ISOTRACK",
    "email": "bobbie.howell@isotrack.com",
    "phone": "+1 (958) 457-2036",
    "address": "597 Middagh Street, Hanover, Vermont, 6626",
    "about": "Nisi ullamco anim non ad ea reprehenderit ipsum cupidatat sunt ex pariatur anim. Veniam labore fugiat id aute culpa esse dolore irure dolore sunt. Reprehenderit occaecat occaecat ipsum voluptate sint. Ex laborum labore cupidatat esse ad eiusmod consectetur ullamco est qui. Anim in voluptate non laborum anim veniam labore velit qui.",
    "registered": "Friday, August 15, 2014 10:20 AM",
    "latitude": "-56.294544",
    "longitude": "3.495156",
    "tags": [
      "sit",
      "laboris",
      "nostrud",
      "elit",
      "aliqua"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Espinoza Glover"
      },
      {
        "id": 1,
        "name": "Bentley Klein"
      },
      {
        "id": 2,
        "name": "Mia Church"
      }
    ],
    "greeting": "Hello, Bobbie! You have 8 unread messages.",
    "favoriteFruit": "banana"
  },
  {
    "_id": "57fd403ed88c66a9ad68f5b5",
    "index": 3,
    "guid": "52542246-f1e3-4b24-8e10-2e6ad8605b36",
    "isActive": true,
    "balance": "$1,166.11",
    "picture": "http://placehold.it/32x32",
    "age": 35,
    "eyeColor": "green",
    "name": {
      "first": "Wilder",
      "last": "Odonnell"
    },
    "company": "KOG",
    "email": "wilder.odonnell@kog.info",
    "phone": "+1 (871) 523-3976",
    "address": "452 Rochester Avenue, Eagleville, Minnesota, 2303",
    "about": "Voluptate ut veniam ea ut consequat elit minim sunt esse et duis exercitation veniam. Occaecat irure velit irure dolor nisi do consequat nostrud ut. Nisi esse sit pariatur aute proident nulla. Adipisicing mollit eu non commodo deserunt in ipsum deserunt reprehenderit. Do cillum qui reprehenderit ut aliqua in ea excepteur proident ut ipsum irure esse.",
    "registered": "Friday, October 23, 2015 8:17 PM",
    "latitude": "-56.375474",
    "longitude": "15.542764",
    "tags": [
      "enim",
      "sunt",
      "enim",
      "tempor",
      "quis"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Diann Donovan"
      },
      {
        "id": 1,
        "name": "Toni Graves"
      },
      {
        "id": 2,
        "name": "Brianna Sanford"
      }
    ],
    "greeting": "Hello, Wilder! You have 5 unread messages.",
    "favoriteFruit": "apple"
  },
  {
    "_id": "57fd403efdc3a6bea5a73a29",
    "index": 4,
    "guid": "89f95fda-5395-4f2a-b596-63abd33a375a",
    "isActive": false,
    "balance": "$3,037.22",
    "picture": "http://placehold.it/32x32",
    "age": 32,
    "eyeColor": "blue",
    "name": {
      "first": "Della",
      "last": "Salazar"
    },
    "company": "NURPLEX",
    "email": "della.salazar@nurplex.me",
    "phone": "+1 (956) 421-2350",
    "address": "182 Rugby Road, Flintville, Texas, 3258",
    "about": "Nisi irure in do aute cillum cupidatat cupidatat. Incididunt dolor anim pariatur esse aliquip labore. Commodo sint id dolor nulla eu sint nostrud aute cillum et in enim amet officia.",
    "registered": "Thursday, September 3, 2015 1:01 AM",
    "latitude": "-4.010268",
    "longitude": "-69.854076",
    "tags": [
      "quis",
      "excepteur",
      "excepteur",
      "eu",
      "amet"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Shelly Ewing"
      },
      {
        "id": 1,
        "name": "Mona Casey"
      },
      {
        "id": 2,
        "name": "Shaw Adams"
      }
    ],
    "greeting": "Hello, Della! You have 9 unread messages.",
    "favoriteFruit": "apple"
  },
  {
    "_id": "57fd403e9b54225f4b0c042a",
    "index": 5,
    "guid": "147df707-d34d-4856-ac2a-218a66712e68",
    "isActive": true,
    "balance": "$3,042.89",
    "picture": "http://placehold.it/32x32",
    "age": 26,
    "eyeColor": "green",
    "name": {
      "first": "Waller",
      "last": "Winters"
    },
    "company": "SEQUITUR",
    "email": "waller.winters@sequitur.co.uk",
    "phone": "+1 (888) 477-2465",
    "address": "756 Montgomery Street, Bridgetown, Massachusetts, 475",
    "about": "Velit ullamco duis adipisicing consectetur sunt amet. Velit eu sit voluptate et sit commodo excepteur adipisicing labore est mollit eiusmod reprehenderit. Eu nulla quis adipisicing aute pariatur deserunt excepteur sunt duis laborum veniam. Deserunt aute deserunt ullamco laborum nostrud qui anim dolore. Commodo consectetur pariatur est commodo. Nulla est aliqua id nostrud elit occaecat laborum laborum labore consectetur nostrud in. Aliquip adipisicing magna fugiat aliqua pariatur officia anim magna dolore tempor laborum aliqua laborum.",
    "registered": "Saturday, March 1, 2014 3:14 AM",
    "latitude": "39.242909",
    "longitude": "-153.855745",
    "tags": [
      "cillum",
      "ut",
      "dolor",
      "aliqua",
      "est"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Odessa Nguyen"
      },
      {
        "id": 1,
        "name": "Hoffman Hester"
      },
      {
        "id": 2,
        "name": "Esmeralda Wood"
      }
    ],
    "greeting": "Hello, Waller! You have 10 unread messages.",
    "favoriteFruit": "apple"
  },
  {
    "_id": "57fd403e96c9583768f2e3d3",
    "index": 6,
    "guid": "466f530a-d8f7-4b97-80f1-508edca8a498",
    "isActive": false,
    "balance": "$3,223.18",
    "picture": "http://placehold.it/32x32",
    "age": 30,
    "eyeColor": "blue",
    "name": {
      "first": "Watts",
      "last": "Walton"
    },
    "company": "MAXIMIND",
    "email": "watts.walton@maximind.io",
    "phone": "+1 (941) 467-2242",
    "address": "102 Senator Street, Warsaw, Iowa, 3626",
    "about": "Sit voluptate aute voluptate et labore dolore elit aliquip est aute ad laborum quis eiusmod. Incididunt veniam pariatur ullamco et ex ex exercitation nostrud dolor pariatur aute. Qui aute magna ea dolor ut amet velit cillum. Labore irure pariatur anim amet nisi nisi ullamco cupidatat.",
    "registered": "Monday, October 26, 2015 8:39 PM",
    "latitude": "2.462394",
    "longitude": "3.086519",
    "tags": [
      "aliquip",
      "minim",
      "commodo",
      "dolore",
      "nulla"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Bridges Bartlett"
      },
      {
        "id": 1,
        "name": "Willis Britt"
      },
      {
        "id": 2,
        "name": "Frieda Key"
      }
    ],
    "greeting": "Hello, Watts! You have 9 unread messages.",
    "favoriteFruit": "strawberry"
  },
  {
    "_id": "57fd403e7053990c8dca65c3",
    "index": 7,
    "guid": "7a06b9e1-2569-44db-ba37-a3acafc16bd1",
    "isActive": false,
    "balance": "$2,900.20",
    "picture": "http://placehold.it/32x32",
    "age": 20,
    "eyeColor": "brown",
    "name": {
      "first": "Ellison",
      "last": "Fischer"
    },
    "company": "QUILTIGEN",
    "email": "ellison.fischer@quiltigen.tv",
    "phone": "+1 (941) 490-2709",
    "address": "932 Seagate Terrace, Murillo, Wyoming, 2635",
    "about": "Sint eu nostrud enim qui consequat. Amet enim irure do in laboris do fugiat ut elit occaecat magna. Consequat dolore nostrud nostrud nulla cupidatat culpa aliqua enim veniam nulla elit reprehenderit amet. Amet tempor id ea in anim eiusmod sunt elit laborum sunt do ea aliquip occaecat.",
    "registered": "Tuesday, November 18, 2014 9:56 PM",
    "latitude": "-17.872504",
    "longitude": "-178.986255",
    "tags": [
      "eu",
      "adipisicing",
      "ad",
      "non",
      "ad"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Becker Richards"
      },
      {
        "id": 1,
        "name": "Anastasia Thomas"
      },
      {
        "id": 2,
        "name": "Beverley Schwartz"
      }
    ],
    "greeting": "Hello, Ellison! You have 6 unread messages.",
    "favoriteFruit": "apple"
  },
  {
    "_id": "57fd403e10e5d59da8c6cfb0",
    "index": 8,
    "guid": "7386fa39-c4f1-4404-b49d-edc45788177a",
    "isActive": false,
    "balance": "$3,689.49",
    "picture": "http://placehold.it/32x32",
    "age": 29,
    "eyeColor": "brown",
    "name": {
      "first": "Shari",
      "last": "Bryan"
    },
    "company": "EZENT",
    "email": "shari.bryan@ezent.name",
    "phone": "+1 (822) 567-3011",
    "address": "890 Corbin Place, Enetai, Virgin Islands, 9157",
    "about": "Voluptate sunt esse dolore ea consectetur ex culpa. Eu est est exercitation eiusmod aliquip pariatur tempor. Laboris sit do nisi commodo amet ullamco duis aute irure anim sunt mollit. Nostrud in enim labore et incididunt cupidatat.",
    "registered": "Thursday, November 27, 2014 3:58 AM",
    "latitude": "64.700531",
    "longitude": "23.535676",
    "tags": [
      "deserunt",
      "magna",
      "consectetur",
      "velit",
      "deserunt"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Stokes Fox"
      },
      {
        "id": 1,
        "name": "Sampson Wade"
      },
      {
        "id": 2,
        "name": "Gonzalez Gray"
      }
    ],
    "greeting": "Hello, Shari! You have 6 unread messages.",
    "favoriteFruit": "banana"
  },
  {
    "_id": "57fd403eeb8c84be2e0a828f",
    "index": 9,
    "guid": "83a0380f-0639-4d10-acb0-9ec27b1605d2",
    "isActive": true,
    "balance": "$2,513.86",
    "picture": "http://placehold.it/32x32",
    "age": 39,
    "eyeColor": "blue",
    "name": {
      "first": "Young",
      "last": "Walter"
    },
    "company": "ENTHAZE",
    "email": "young.walter@enthaze.ca",
    "phone": "+1 (883) 555-3102",
    "address": "590 Elliott Place, Kraemer, Florida, 1153",
    "about": "Aute voluptate laboris cillum adipisicing ullamco sit ut nisi cillum voluptate ad. Culpa consequat aliquip est consectetur eu sint ipsum excepteur duis do est. Do mollit pariatur veniam laborum labore ipsum officia aliqua id cillum est. Fugiat in nulla ex ex reprehenderit voluptate fugiat nisi cillum sint nisi excepteur velit sit. Minim proident ea cupidatat in aliqua.",
    "registered": "Saturday, September 12, 2015 6:03 AM",
    "latitude": "-57.767683",
    "longitude": "-119.498369",
    "tags": [
      "nulla",
      "incididunt",
      "veniam",
      "et",
      "proident"
    ],
    "range": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9
    ],
    "friends": [
      {
        "id": 0,
        "name": "Trina Wiley"
      },
      {
        "id": 1,
        "name": "Reva Castro"
      },
      {
        "id": 2,
        "name": "Carissa Ray"
      }
    ],
    "greeting": "Hello, Young! You have 7 unread messages.",
    "favoriteFruit": "strawberry"
  }
]
var json_parse = function() {
  var at, // The index of the current character
      ch, //the current character
      escapee = {
        '"': '"',
        '||': '||',
        '/': '/',
        b: 'b',
        f: '\f',
        n: '\n',
        r: '\r',
        t: '\t'
      },
      text,
      error = function(m) {
        throw {
          name: 'SyntaxError',
          message: m,
          at: at,
          text: text
        };
      },
      next = function(c) {
        // If param c is provided, verify that it matches the current char.
        if (c && c !== ch) {
          error("Expected '" + c + "' instead of '" + ch + "'");
        }
        
        // Get the next char, when there are 0 left, return the empty string
        ch = text.charAt(at);
        at += 1;
        return ch;
      },
      
      number = function() {
        var number;
        var string = '';
        
        if (ch === '-') {
          string = '-';
          next('-');
        }
        while (ch >= '0' && ch <= '9') {
          string += ch;
          next();
        }
        if (ch === '.') {
          string += '.';
          while (next() && ch >= '0' && ch <= '9') {
            string += ch;
          }
        }
        if (ch === 'e' || ch === 'E') {
          string += ch;
          next();
          if (ch === '-' || ch === '+') {
            string += ch;
            next();
          }
          while (ch >= '0' && ch <= '9') {
            string += ch;
            next();
          }
        }
        number = +string;
        if (isNaN(number)) {
          error("Bad number");
        } else {
          return number;
        }
      },
      string = function() {
        var hex,
            i,
            string = '',
            uffff;
            
            if (ch === '"') {
              while (next()) {
                if (ch === '"') {
                  next();
                  return string;
                } else if (ch === '\\') {
                  next();
                  if (ch === 'u') {
                    uffff = 0;
                    for (i = 0; i < 4; i += 1) {
                      hex = parseInt(next(), 16);
                      if (!isFinite(hex)) {
                        break;
                      }
                      uffff = uffff * 16 + hex;
                    }
                    string += String.fromCharCode(uffff);
                  } else if (typeof escapee[ch] === 'string') {
                    string+= excapee[ch];
                  } else {
                      break;
                  }
                } else {
                    string += ch;
                }
              }
            }
            error("Bad string");
      },
      
      white = function() {
        // Skip whitespace
        while (ch && ch <= ' ') {
          next();
        }
      },
      
      word = function() {
        // true, false or null
        
        switch (ch) {
          case 't':
            next('t');
            next('r');
            next('u');
            next('e');
            return true;
          case 'f':
            next('f');
            next('a');
            next('l');
            next('s');
            next('e');
            return true;
          case 'n':
            next('n');
            next('e');
            next('x');
            next('t');
            return null;
        }
        error("Unexpected '" + ch + "'");
      },
      
      value, // placeholder for the value function
      array = function() {
        var array = [];
        
        if (ch === '[') {
          next('[');
          white();
          if (ch === ']') {
            next(']');
            return array;
          }
          while (ch) {
            array.push(value());
            white();
            if (ch ===']') {
              next(']');
              return array;
            }
            next(',');
            white();
          }
        }
        error("Bad array");
      },
      
      object = function() {
        var key,
            object = {};
            
            if (ch === '{') {
              next('{');
              white();
              if (ch === '}') {
                next('}');
                return object;
              }
              while (ch) {
                key = string();
                white();
                next(':');
                object[key] = value();
                white();
                if (ch === '}') {
                  next('}');
                  return object;
                }
                next(',');
                white();
              }
            }
            error("Bad object");
      };
      
      // Parse a JSON value (object, array, string, number or word)
      value = function() {
        white();
        switch (ch) {
          case '{':
            return object();
          case '[':
            return array();
          case '"':
            return string();
          case '-':
            return number();
          default:
            return ch >= '0' && ch <= '9' ? number() : word();
        }
      };
      
      // Return json_parse function with access to all the above functions and variables.
      return function(source, reviver) {
        var result;
        
        text = source;
        at = 0;
        ch = ' ';
        result = value();
        white();
        if (ch) {
          error("Syntax error");
        }
        
        return typeof reviver === 'function'
          ? function walk(holder, key) {
            var k,
                v,
                value = holder[key];
            if (value && typeof value === 'object') {
              for (k in value) {
                if (Object.hasOwnProperty.call(value, k)) {
                  v = walk(value, k);
                  if (v !== undefined) {
                    value[k] = v;
                  } else {
                    delete value[k];
                  }
                }
              }
            }
            return reviver.call(holder, key, value);
          }({'': result}, '')
            
            : result;
      };
}();

json-parse

This Gist was automatically created by Carbide, a free online programming environment.

You can view a live, interactive version of this Gist here.