Chromium Code Reviews| Index: tools/json_schema_compiler/json_parse.py |
| diff --git a/tools/json_schema_compiler/json_parse.py b/tools/json_schema_compiler/json_parse.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..563faef5f9d1c539448755e0e076468a90e442a8 |
| --- /dev/null |
| +++ b/tools/json_schema_compiler/json_parse.py |
| @@ -0,0 +1,35 @@ |
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import json |
| +import os |
| +import sys |
| + |
| +try: |
| + from collections import OrderedDict |
| +except ImportError: |
| + from ordered_dict import OrderedDict |
| + |
|
not at google - send to devlin
2012/11/16 18:45:56
Can we incorporate this file into ordered_dict.py?
cduvall
2012/11/17 01:55:12
Done.
|
| +SYS_PATH = sys.path[:] |
| +try: |
| + _FILE_PATH = os.path.dirname(os.path.realpath(__file__)) |
| + _SIMPLE_JSON_PATH = os.path.join(_FILE_PATH, |
| + os.pardir, |
| + os.pardir, |
| + 'simplejson') |
| + sys.path.insert(0, _SIMPLE_JSON_PATH) |
| + import simplejson |
| + _COMMENT_EATER_PATH = os.path.join(_FILE_PATH, os.pardir) |
| + sys.path.insert(0, _COMMENT_EATER_PATH) |
| + import json_comment_eater |
| +finally: |
| + sys.path = SYS_PATH |
| + |
| + |
| +def Parse(json_str): |
| + json_str = json_comment_eater.Nom(json_str) |
| + try: |
| + return json.loads(json_str, object_pairs_hook=OrderedDict) |
| + except TypeError: |
| + return simplejson.loads(json_str, object_pairs_hook=OrderedDict) |