Example #1
0
def parseWithSafeJSON():
	count = 0
	for jsonString in [SAMPLE_JSON_1, SAMPLE_JSON_2, SAMPLE_JSON_3]:
		count += 1
		print 'Object {0}:'.format(count)
		o1 = safeJSON.loads(jsonString)

		# print first result name
		if o1['results'][0]['name']:
			print "Name: {0}".format(o1['results'][0]['name'])

		# print first child name
		if o1['results'][0]['child_items'][0]['name']:
			print o1['results'][0]['child_items'][0]['name']
Example #2
0
def parseWithSafeJSON():
    count = 0
    for jsonString in [SAMPLE_JSON_1, SAMPLE_JSON_2, SAMPLE_JSON_3]:
        count += 1
        print 'Object {0}:'.format(count)
        o1 = safeJSON.loads(jsonString)

        # print first result name
        if o1['results'][0]['name']:
            print "Name: {0}".format(o1['results'][0]['name'])

        # print first child name
        if o1['results'][0]['child_items'][0]['name']:
            print o1['results'][0]['child_items'][0]['name']
Example #3
0
 def testLoads(self):
     logger.info("Testing loads")
     testObject = {
         'testInt': 1,
         'testString': 'String',
         'testArray': ['item1', 'item2', 3],
         'testDict': {
             'dictKey1': 'dictVal1',
             'dictKey2': 'dictVal2'
         },
         'testNested1': [{
             'dictKey3': [1, 2, 3]
         }],
         'testNested2': {
             'dictKey4': [1, 2, 3]
         }
     }
     jsonString = json.dumps(testObject)
     safeJsonObject = safeJSON.loads(jsonString)
     self.doTestLoadLoads(testObject, safeJsonObject)
Example #4
0
	def testLoads(self):
		logger.info("Testing loads")
		testObject = {
			'testInt' : 1,
			'testString' : 'String',
			'testArray' : ['item1','item2',3],
			'testDict' : {
				'dictKey1' : 'dictVal1',
				'dictKey2' : 'dictVal2'
			},
			'testNested1' : [{
				'dictKey3' : [1,2,3]
			}],
			'testNested2' : {
				'dictKey4' : [1,2,3]
			}
		}
		jsonString = json.dumps(testObject)
		safeJsonObject = safeJSON.loads(jsonString)
		self.doTestLoadLoads(testObject, safeJsonObject)