/** var $j = pulp.json; */
pulp.Modules.json = '$j';

(function() {
  
  // feature test for native JSON stringify and parse functions
  var	s, p, $j, isStandard = false;
  if (window.JSON && (s = JSON.stringify) && (p = JSON.parse)) {
    var undef,
      fn = pulp.EmptyFunction,
      special = s('"\b\t\n\f\r\\'),
      cyclic = [],
      o = p('[false,true,null,"\\u0001\\u0000",5,5.1,{"a":1,"a2":{"b":"two"}}]')
    ;
    cyclic[0] = cyclic;
    function cls(c){
      this.c = c;
    }
    cls.prototype.d = fn;
// TODO: check pre-process and revive functions
// TODO: check if whitelist param is working
// don't worry about space formatting		
    try {
      if (
        s(undefined) === undefined &&
        s([undefined]) == '[null]' &&
        s(fn) === undefined &&
        s([fn]) == '[null]' &&
        s([undefined, undef, null, false, true, Infinity, NaN, '\u0001\u0000', 5, 5e2, 5e-2, 5.1, 5.1e2, 5.1e-2, {a: 1, a2: {b: 'two'}}]) ==
          '[null,null,null,false,true,null,null,"\\u0001\\u0000",5,500,0.05,5.1,510,0.051,{"a":1,"a2":{"b":"two"}}]' &&
        (special === '"\\"\\b\\t\\n\\f\\r\\\\"' || special === '"\\"\\u0008\\u0009\\u000a\\u000c\\u000d\\\\"') &&
        (/2009-01-(1[456])T\d\d:00:00(.000)?Z/).test(s(new Date(2009,0,15,12,0,0,0))) &&
        s(new cls('cee')) == '{"c":"cee"}' &&
        o[0] === false &&
        o[1] === true &&
        o[2] === null &&
        o[3] === "\u0001\u0000" &&
        o[4] === 5 &&
        o[5] === 5.1 &&
        o[6].a === 1 &&
        o[6].a2.b == 'two'
      ) {			
        try {
          s(cyclic);
        } 
        catch (e2) {
          // e should be a TypeError, but we won't get that picky
          isStandard = true;
        }
      }
    } catch (e) {}
  }
  // end feature test

  $j = (isStandard ? window.JSON : YUI_JSON); 
  // keep the global namespace clean
//	delete window.YUI_JSON;
  /**
   * Import the libraries from json.org
   * @namespace
   */
  pulp.json = $j;
  pulp.json.usingNative = isStandard;
  pulp.json.encode = pulp.json.serialize = $j.stringify;
  pulp.json.decode = pulp.json.unserialize = $j.parse;
  
//	cls = $j = null;
})();
