code: def _ConvertPathSpecToDict(cls, path_spec_object):
      
      if not isinstance(path_spec_object, dfvfs_path_spec.PathSpec):
        raise TypeError
  
      json_dict = {'__type__': 'PathSpec'}
      for property_name in dfvfs_path_spec_factory.Factory.PROPERTY_NAMES:
        property_value = getattr(path_spec_object, property_name, None)
        if property_value is not None:
          json_dict[property_name] = property_value
  
      if path_spec_object.HasParent():
        json_dict['parent'] = cls._ConvertPathSpecToDict(path_spec_object.parent)
  
      json_dict['type_indicator'] = path_spec_object.type_indicator
      location = getattr(path_spec_object, 'location', None)
      if location:
        json_dict['location'] = location
  
      return json_dict
docs: Converts a path specification object into a JSON dictionary.
  
      The resulting dictionary of the JSON serialized objects consists of:
      {
          '__type__': 'PathSpec'
          'type_indicator': 'OS'
          'parent': { ... }
          ...
      }
  
      Here '__type__' indicates the object base type. In this case 'PathSpec'.
      The rest of the elements of the dictionary make up the path specification
      object properties. The supported property names are defined in
      path_spec_factory.Factory.PROPERTY_NAMES. Note that this method is called
      recursively for every path specification object and creates a dict of
      dicts in the process.
  
      Args:
        path_spec_object (dfvfs.PathSpec): path specification.
  
      Returns:
        dict[str, object]: JSON serialized objects.
  
      Raises:
        TypeError: if not an instance of dfvfs.PathSpec.