<p>I'm attempting to migrate a helm/kubernetes codebase to <a href="https://github.com/dhall-lang/dhall-kubernetes" rel="nofollow noreferrer">dhall-kubernetes</a>. Dhall is typed, so I need to provide full records with optional fields set to null if there were not set. So I'm looking for something like <code>kubectl get objname id -o yaml</code>, but I need it to output all optional fields like <code>fieldName: null</code>. Is there a way to accomplish this? I don't know how to do it, so as a plan B I wrote <a href="https://github.com/dredozubov/dhall-default" rel="nofollow noreferrer">dhall-default</a> and I attempt to approach it in a different way.</p>

<p>I'll turn @sjakobi's solution into an answer like @dredozubov suggested</p>

<p>You can pass the desired type from <code>dhall-kubernetes</code> to <code>yaml-to-dhall</code> and it will generate the equivalent Dhall code, albeit without any simplifications.</p>

<p>As an example, suppose that you have the following Kubernetes resource:</p>

<pre><code># ./nginx.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      name: nginx
  template:
    metadata:
      name: nginx
    spec:
      containers:
        - image: nginx:1.15.3
          name: nginx
          ports:
            - containerPort: 80
</code></pre>

<p>... and the following Dhall type for a Kubernetes deployment:</p>

<pre><code>-- ./Deployment.dhall

let kubernetes = https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/506d633e382872346927b8cb9884d8b7382e6cab/package.dhall

in  kubernetes.Deployment.Type
</code></pre>

<p>Then you can translate the YAML to Dhall by running:</p>

<pre><code>$ yaml-to-dhall --file ./nginx.yaml ./Deployment.dhall
</code></pre>

<p>The output is a bit large (~1300 lines), because <code>yaml-to-dhall</code> doesn't yet take advantage of support for default values, so I won't include the output here.</p>

<p>If you pipe the result back into <code>dhall-to-yaml</code> then you will get the original Resource (albeit with fields sorted):</p>

<pre><code>$ yaml-to-dhall --file ./nginx.yaml ./Deployment.dhall | dhall-to-yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      name: nginx
  template:
    metadata:
      name: nginx
    spec:
      containers:
        - image: nginx:1.15.3
          name: nginx
          ports:
            - containerPort: 80
</code></pre>

<p>... and if you supply the <code>--preserve-null</code> option to <code>dhall-to-yaml</code> it will preserve all <code>null</code> fields as the question requests:</p>

<pre><code>$ yaml-to-dhall --file ./nginx.yaml ./Deployment.dhall | dhall-to-yaml --preserve-null 
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations: null
  clusterName: null
  creationTimestamp: null
  deletionGracePeriodSeconds: null
  deletionTimestamp: null
  finalizers: null
  generateName: null
  generation: null
  labels: null
  managedFields: null
  name: nginx
  namespace: null
  ownerReferences: null
  resourceVersion: null
  selfLink: null
  uid: null
spec:
  minReadySeconds: null
  paused: null
  progressDeadlineSeconds: null
  replicas: 2
  revisionHistoryLimit: null
  selector:
    matchExpressions: null
    matchLabels:
      name: nginx
  strategy: null
  template:
    metadata:
      annotations: null
      clusterName: null
      creationTimestamp: null
      deletionGracePeriodSeconds: null
      deletionTimestamp: null
      finalizers: null
      generateName: null
      generation: null
      labels: null
      managedFields: null
      name: nginx
      namespace: null
      ownerReferences: null
      resourceVersion: null
      selfLink: null
      uid: null
    spec:
      activeDeadlineSeconds: null
      affinity: null
      automountServiceAccountToken: null
      containers:
        - args: null
          command: null
          env: null
          envFrom: null
          image: nginx:1.15.3
          imagePullPolicy: null
          lifecycle: null
          livenessProbe: null
          name: nginx
          ports:
            - containerPort: 80
              hostIP: null
              hostPort: null
              name: null
              protocol: null
          readinessProbe: null
          resources: null
          securityContext: null
          startupProbe: null
          stdin: null
          stdinOnce: null
          terminationMessagePath: null
          terminationMessagePolicy: null
          tty: null
          volumeDevices: null
          volumeMounts: null
          workingDir: null
      dnsConfig: null
      dnsPolicy: null
      enableServiceLinks: null
      ephemeralContainers: null
      hostAliases: null
      hostIPC: null
      hostNetwork: null
      hostPID: null
      hostname: null
      imagePullSecrets: null
      initContainers: null
      nodeName: null
      nodeSelector: null
      overhead: null
      preemptionPolicy: null
      priority: null
      priorityClassName: null
      readinessGates: null
      restartPolicy: null
      runtimeClassName: null
      schedulerName: null
      securityContext: null
      serviceAccount: null
      serviceAccountName: null
      shareProcessNamespace: null
      subdomain: null
      terminationGracePeriodSeconds: null
      tolerations: null
      topologySpreadConstraints: null
      volumes: null
status: null
</code></pre>
