diff options
Diffstat (limited to 'json.mll')
-rw-r--r-- | json.mll | 70 |
1 files changed, 52 insertions, 18 deletions
@@ -1,9 +1,58 @@ -(* Very minimal standard-compliant JSON parser/generator, because the currently - * available JSON libraries for OCaml try to do too much and have too many - * dependencies. +(* Copyright (c) 2010-2011 Yoran Heling + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *) + +(* This is a very minimal standard-compliant JSON parser/generator, because the + * currently available JSON libraries for OCaml try to do too much and have too + * many dependencies. + * * - The aim of this library is to be small rather than fast. + * It was made to parse and generate small (~1kB to 100kB) messages. + * Performance should be acceptable as long as the input does not contain long + * strings with a lot of escaped characters. (e.g. binary data encoded in a + * JSON string is a bad idea.) + * * - Error detecting is correct. Error reporting, however, is rather minimal. + * + * - This library conforms to RFC 4627, with two exceptions: + * 1. The top-level JSON value does not have to be an array or object, but can + * be any valid JSON value. An application would have to check for the type + * of the value anyway. + * 2. All data after the end of the JSON string is ignored, and may thus + * contain garbage. For example, the following JSON string is valid: + * true{"data":1} + * Parsing that will simply give you (Bool true) + * + * - All data is assumed to be encoded in UTF-8 + * In particular: + * - When parsing, \uxxxx string escapes are converted into their UTF-8 + * representation. + * - When serializing, all non-printable 7-bit string characters are escaped + * to their native JSON control character (e.g. \b or \t) or as \u00xx. + * Everything else is passed as-is. + * + * Note that I have not fully tested how this library reacts to various forms of + * JSON input, but I do not expect any major problems. * (Some portions and ideas of this code were borrowed from yojson) + * *) @@ -249,18 +298,3 @@ let get_value obj key = } - - - - -(* Testing stuff... - -#load "_build/json.cmo";; -open Json;; -get_bool;; - -let obj = json_of_string "{\"num\":1,\"more\":false,\"items\":[{\"language\":\"ja\",\"original\":null,\"name\":\"Studi\\u007Fo e.go!\",\"type\":\"co\",\"id\":17}]}";; -string_of_json obj;; - -*) - |