Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Node Traversal - get attribute #34

Closed
scottwinkler opened this issue Mar 31, 2020 · 2 comments
Closed

JSON Node Traversal - get attribute #34

scottwinkler opened this issue Mar 31, 2020 · 2 comments

Comments

@scottwinkler
Copy link
Owner

scottwinkler commented Mar 31, 2020

Currently, complex JSON is flattened into an outputs map. It would be nice to also a way to easily get nested JSON values at the top level. I propose adding a new output value called get to do this (potentially deprecating the output attribute). For example, in the following JSON

{
  "last_state_loss_time": 0,
  "spark_version": "5.3.x-scala2.11",
  "azure_attributes": [8, 17, 20 ],
  "state": "PENDING",
  "enable_elastic_disk": true,
  "init_scripts_safe_mode": false,
  "num_workers": 1,
  "driver_node_type_id": "Standard_D3_v2",
  "default_tags": {
    "Creator": "lagripp@microsoft.com",
    "ClusterName": "my-cluster",
    "ClusterId": "0327-174802-howdy690",
    "Vendor": "Databricks"
  }
} 

The ClusterName attribute could be read with the following expression:
shell_script.test.get["default_tags.ClusterName"].asString

the get object has the following attributes. It will try to cast a value into as many fields as possible. If it cannot set a field, it will use nil, or perhaps the default no-value if nil does not work.

get = {
  asString = string
  asNumber = number
  asBool = bool
  asList = list(string)
  asMap = map(string)
}

To get a value from a List you could do:
tonumber(shell_script.test.get["azure_attributes"].asList[1])

Alternatively you can /refer to individual elements with the [] accessor. For example:

shell_script.test.get["azure_attributes.[1]"]asNumber returns the number 17

@syyang-in-cloud
Copy link

Hello, I am writing many of my resources/data sources using this shell provider. Thanks!
I got into this issue today, and I'm glad to see this issue is created here.

@scottwinkler
Copy link
Owner Author

replaced with #88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants