Every line of 'array to json python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
136 @get_items.register(list) 137 def _json_array(obj): 138 return enumerate(obj)
146 def as_array(obj): 147 """ 148 Creates an json-like representation of a variable, supporting types with a `.to_array()` function. 149 150 :rtype: dict|list|str|int|float|bool|None 151 """ 152 if hasattr(obj, "to_array"): 153 return obj.to_array() 154 elif isinstance(obj, (list, tuple)): 155 return [as_array(x) for x in obj] 156 elif isinstance(obj, dict): 157 return {key:as_array(obj[key]) for key in obj.keys()} 158 else: 159 _json_dumps(obj) # raises error if is wrong json 160 return obj
121 def to_json(self, value): 122 return list(map(self.space.to_json, value))
25 def python_to_json(python_data): 26 '''Convert python data (tuple, list, dict, etc) into json string''' 27 json_str = json.dumps(python_data, indent=4) 28 return json_str
41 def make_array(key, data): 42 result = [] 43 for item in data: 44 result.append(item.get(key)) 45 return str(json.dumps(result))
190 def _array_from_json(self, json_obj, writers_schema, readers_schema): 191 return [self._generic_from_json(x, writers_schema.items, readers_schema.items) 192 for x in json_obj]