'error converting YAML to JSON: yaml: found character that cannot start any token

I get the error from the title when I try to run a Helm chart that contains the following code:

{{ if eq .Values.environment "generic" }}
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: core-ingress
  annotations:
    kubernetes.io/ingress.class: {{ .Values.core_ingress.class }}
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    host: {{ .Values.core_ingress.host }} 
    http:
      paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: {{ .Values.core_ingress.service }}
              port:
                number: {{ .Values.core_ingress.port }}
{{ end }}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source