Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: tools/json_schema_compiler/json_parse.py

Issue 11079010: Extensions Docs Server: Preserve JSON declaration order in extensions documentation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use OrderedDict for JSON parsing Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import json
6 import os
7 import sys
8
9 try:
10 from collections import OrderedDict
11 except ImportError:
12 from ordered_dict import OrderedDict
13
14 SYS_PATH = sys.path[:]
15 try:
16 _FILE_PATH = os.path.dirname(os.path.realpath(__file__))
17 _SIMPLE_JSON_PATH = os.path.join(_FILE_PATH,
18 os.pardir,
19 os.pardir,
20 'simplejson')
21 sys.path.insert(0, _SIMPLE_JSON_PATH)
22 import simplejson
23 _COMMENT_EATER_PATH = os.path.join(_FILE_PATH, os.pardir)
24 sys.path.insert(0, _COMMENT_EATER_PATH)
25 import json_comment_eater
26 finally:
27 sys.path = SYS_PATH
28
29
30 def Parse(json_str):
31 json_str = json_comment_eater.Nom(json_str)
32 try:
33 return json.loads(json_str, object_pairs_hook=OrderedDict)
34 except:
35 return simplejson.loads(json_str, object_pairs_hook=OrderedDict)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698