code: func Marshal(
  	config *configs.Config,
  	p *plans.Plan,
  	sf *statefile.File,
  	schemas *terraform.Schemas,
  	stateSchemas *terraform.Schemas,
  ) ([]byte, error) {
  	if stateSchemas == nil {
  		stateSchemas = schemas
  	}
  
  	output := newPlan()
  	output.TerraformVersion = version.String()
  
  	err := output.marshalPlanVariables(p.VariableValues, schemas)
  	if err != nil {
  		return nil, fmt.Errorf("error in marshalPlanVariables: %s", err)
  	}
  
  	// output.PlannedValues
  	err = output.marshalPlannedValues(p.Changes, schemas)
  	if err != nil {
  		return nil, fmt.Errorf("error in marshalPlannedValues: %s", err)
  	}
  
  	// output.ResourceChanges
  	err = output.marshalResourceChanges(p.Changes, schemas)
  	if err != nil {
  		return nil, fmt.Errorf("error in marshalResourceChanges: %s", err)
  	}
  
  	// output.OutputChanges
  	err = output.marshalOutputChanges(p.Changes)
  	if err != nil {
  		return nil, fmt.Errorf("error in marshaling output changes: %s", err)
  	}
  
  	// output.PriorState
  	if sf != nil && !sf.State.Empty() {
  		output.PriorState, err = jsonstate.Marshal(sf, stateSchemas)
  		if err != nil {
  			return nil, fmt.Errorf("error marshaling prior state: %s", err)
  		}
  	}
  
  	// output.Config
  	output.Config, err = jsonconfig.Marshal(config, schemas)
  	if err != nil {
  		return nil, fmt.Errorf("error marshaling config: %s", err)
  	}
  
  	ret, err := json.Marshal(output)
  	return ret, err
  }
docs: // Marshal returns the json encoding of a terraform plan.