Difficulty accessing nested values in TOML

89 Views Asked by At

I'm trying to adapt an Express app to CloudFlare Functions. As I understand it, Functions/serverless doesn't really support anything that needs to read from a file system. And so the advice apparently is to subsume my config values into my wrangler.toml file.

Here's my JSON:

{
  "zero": "etc",
  "one": {
    "two": {
      "three": "four"
    }
  }
}

This JSON-to-TOML util gave me:

zero = "etc"

[one.two]
three = "four"

I put that into my wrangler.toml right under the [vars] section heading and start the server, which it tells me:

Your worker has access to the following bindings:
- Vars:
  - zero: "etc"

Why aren't my nested values coming through?

1

There are 1 best solutions below

0
On

that's going to be a very un-fun half an hour to do that conversion manually

You could use the command-line tool tomlq from kislyuk/yq to automate the JSON-to-TOML conversion. A provided filter is run internally using jqlang/jq, so any kind of transformation can be applied to it on the fly. For example, given your JSON sample as input.json, to wrap everything below [vars] you can run:

tomlq -n -t '{vars: $j[]}' --slurpfile j input.json
[vars]
zero = "etc"

[vars.one.two]
three = "four"