class_docstr: Defines a single training or test example.
  
  Stores each column of the example as an attribute.
code: def fromJSON(cls, data, fields):
      ex = cls()
      obj = json.loads(data)
  
      for key, vals in fields.items():
          if vals is not None:
              if not isinstance(vals, list):
                  vals = [vals]
  
              for val in vals:
                  # for processing the key likes 'foo.bar'
                  name, field = val
                  ks = key.split(".")
  
                  def reducer(obj, key):
                      if isinstance(obj, list):
                          results = []
                          for data in obj:
                              if key not in data:
                                  # key error
                                  raise ValueError(
                                      "Specified key {} was not found in "
                                      "the input data".format(key)
                                  )
                              else:
                                  results.append(data[key])
                          return results
                      else:
                          # key error
                          if key not in obj:
                              raise ValueError(
                                  "Specified key {} was not found in "
                                  "the input data".format(key)
                              )
                          else:
                              return obj[key]
  
                  v = reduce(reducer, ks, obj)
                  setattr(ex, name, field.preprocess(v))
      return ex
  
file_path: pytext/pytext/legacy/data/example.py
imports: import json
  from functools import reduce
label_desc: Use image node_id 1 for calling the Example obj's underlying member method code with example usage: obj.fromJSON(cls, data, fields) and returns: ex, results, obj