import json
from veusz.plugins import *

class ImportJSON(ImportPlugin):
    """
    Read data from JSON file
    """

    name = "LoadJSON"
    author = "Brunetto Ziosi <brunetto.ziosi@gmail.com>"
    description = "Reads data form a JSON file"

    # Uncomment this line for the plugin to get its own tab
    promote_tab='LoadJSON'

    file_extensions = set(['.json'])

    def __init__(self):
        ImportPlugin.__init__(self)
        self.fields = [
            ImportFieldText("name", descr="Dataset name", default="name"),
            ]

    def doImport(self, params):
        """Actually import data
        params is a ImportPluginParams object.
        Return a list of ImportDataset1D, ImportDataset2D objects
        """
        f = params.openFileWithEncoding()
        data = []
        tmp = json.load(f)
        for name, value in iter(sorted(tmp.iteritems())):
            data.append(ImportDataset1D(name, value))
            print name, len(value), len(data)
        return data

# add the class to the registry. An instance also works, but is deprecated
importpluginregistry.append(ImportPluginExample)

@@ -5,16 +5,35 @@
 rt json%0A
+import numpy as np%0A
 from veu
@@ -808,16 +808,38 @@
 ta = %5B%5D%0A
+        errbar = None%0A
         
@@ -857,16 +857,16 @@
 load(f)%0A
-
         
@@ -919,106 +919,248 @@
 )):%0A
-            data.append(ImportDataset1D(name, value))%0A            print 
+%09%09%09if name.endswith(%22errbar%22):%0A%09%09%09%09errbar=value%0A%09%09%09%09continue%0A%09%09%09elif name.endswith(%22y%22):%0A%09%09%09%09data.append(ImportDataset1D(name=name, data=value, serr=errbar))%0A%09%09%09%09errbar=None%0A%09%09%09%09continue%0A%09%09%09else:%0A%09%09%09%09data.append(ImportDataset1D(
 name, 
-len(
 value)
-, len(data
 )%0A  
@@ -1291,19 +1291,10 @@
 port
-PluginExample
+JSON
 )%0A

deal with errbars