python json object array not serializable
<p>I have a class and array in a loop. I'm filling the object and appending it to the array. How do I pass array data to web side through JSON? I have an error that says JSON  is not serializable. How can I serialize to a JSON?</p>

<pre><code>class myclass(object):
    def __init__(self,vehicle,mng01):
        self.vehicle = vehicle
        self.vehicle = vehicle

#--Main function--
@subApp.route('/jsontry', method=['POST'])
def data():
    for x in list:
        vehicle_sum.append(myclass( x,str(mng01))

    return json.dumps({'success':'1','vehicle':vehicle_sum})
</code></pre>

<p>It doesn't say that JSON is not serializable, it says that your instances of <code>myclass</code> are not JSON serializable. I.e. they cannot be represented as JSON, because it is really not clear what do you expect as an output.</p>

<p>To find out how to make a class JSON serializable, check this question: <a href="http://stackoverflow.com/questions/3768895/how-to-make-a-class-json-serializable">How to make a class JSON serializable</a></p>

<p>In this trivial case, depending on what exactly you're trying to achieve, you might be good with inserting <code>[x.vehicle for x in vehicle_sum]</code> in your JSON. If you really need to insert your instances data in JSON in a direct way, you'll have to write an encoder.</p>

python json ajax serialization