// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* @fileoverview Provides JSON utilities that uses native JSON parsing where19* possible (a feature not currently offered by Closure).20*/2122goog.provide('bot.json');2324goog.require('bot.userAgent');25goog.require('goog.json');26goog.require('goog.userAgent');272829/**30* @define {boolean} NATIVE_JSON indicates whether the code should rely on the31* native `JSON` functions, if available.32*33* <p>The JSON functions can be defined by external libraries like Prototype34* and setting this flag to false forces the use of Closure's goog.json35* implementation.36*37* <p>If your JavaScript can be loaded by a third_party site and you are wary38* about relying on the native functions, specify39* "--define bot.json.NATIVE_JSON=false" to the Closure compiler.40*/41bot.json.NATIVE_JSON = true;424344/**45* Whether the current browser supports the native JSON interface.46* @const47* @see http://caniuse.com/#search=JSON48* @private {boolean}49*/50bot.json.SUPPORTS_NATIVE_JSON_ =51// List WebKit first since every supported version supports52// native JSON (and we can compile away large chunks of code for53// individual fragments by setting the appropriate compiler flags).54goog.userAgent.WEBKIT ||55(goog.userAgent.GECKO && bot.userAgent.isEngineVersion(3.5)) ||56(goog.userAgent.IE && bot.userAgent.isEngineVersion(8));575859/**60* Converts a JSON object to its string representation.61* @param {*} jsonObj The input object.62* @param {?(function(string, *): *)=} opt_replacer A replacer function called63* for each (key, value) pair that determines how the value should be64* serialized. By default, this just returns the value and allows default65* serialization to kick in.66* @return {string} A JSON string representation of the input object.67*/68bot.json.stringify = bot.json.NATIVE_JSON && bot.json.SUPPORTS_NATIVE_JSON_ ?69JSON.stringify : goog.json.serialize;707172/**73* Parses a JSON string and returns the result.74* @param {string} jsonStr The string to parse.75* @return {*} The JSON object.76* @throws {Error} If the input string is an invalid JSON string.77*/78bot.json.parse = JSON.parse;798081