code: def read_json(path, encoding="utf-8", fields=None, dropna=True):
      r"""
      Construct a generator to read json items.
  
      :param path: file path
      :param encoding: file's encoding, default: utf-8
      :param fields: json object's fields that needed, if None,
          all fields are needed. default: None
      :param dropna: whether to ignore and drop invalid data,
          if False, raise ValueError when reading invalid data. default: True
      :return: generator, every time yield (line number, json item)
      """
  
      if fields:
          fields = set(fields)
      with open(path, "r", encoding=encoding) as f:
          for line_idx, line in enumerate(f):
              data = json.loads(line)
              if fields is None:
                  yield line_idx, data
                  continue
              _res = {}
              for k, v in data.items():
                  if k in fields:
                      _res[k] = v
              if len(_res) < len(fields):
                  if dropna:
                      continue
                  else:
                      raise ValueError(
                          "invalid instance at line: {0}".format(
                              line_idx
                          )
                      )
              yield line_idx, _res
  
imports: import os
  import json
  import csv
label_desc: Use image node_id 2 for calling a global function with example usage: read_json(path, encoding, fields, dropna) without return types