Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The article goes on to talk about Jsonnet, which takes the exact approach you describe - it generates JSON by aiming to be a "templated JSON" where the templating involves generating semantic objects, not strings.

Here's an example (adapted from some real-world code) where I specify the k8s cpu limit in one place, and then look up that info in several other places to avoid needing to change multiple values later:

    {
      local container = self,
      requests: {cpu: 5.5, memory: "2G"},
      limits: container.requests + {memory: "4G"},
      environment: [
        {
          name: "NUM_THREADS",
          value: std.toString(std.ceil(container.requests.cpu)),
        },
      ],
    }
Note how I can patch the container.requests object with an alternate memory limit, and how I can calculate an expression for the NUM_THREADS value in order to automatically set it to ceil() of the requested cpu.

(edited for nicer formatting of the code)



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: