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

stringvalidator: Support json string validation #86

Closed
1 task done
k-yomo opened this issue Dec 18, 2022 · 4 comments
Closed
1 task done

stringvalidator: Support json string validation #86

k-yomo opened this issue Dec 18, 2022 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@k-yomo
Copy link

k-yomo commented Dec 18, 2022

Terraform CLI and Framework Versions

❯ terraform version
Terraform v1.3.6
on darwin_arm64
...

❯ go list -m github.com/hashicorp/terraform-plugin-framework
github.com/hashicorp/terraform-plugin-framework v1.0.0

Use Cases

[]validator.String{
  stringvalidator.JSON(),
},

Proposal

It would be very handy if we have json string validator in this package to validate if the given string is valid json or not.

Additional Information

Equivalent implementation in terraform-plugin-sdk package
https://github.com/hashicorp/terraform-plugin-sdk/blob/aa73507131cb35683a6408b4d06252991fecb868/helper/validation/strings.go#L209-L222

Code of Conduct

  • I agree to follow this project's Code of Conduct
@k-yomo k-yomo added the enhancement New feature or request label Dec 18, 2022
@bflad
Copy link
Contributor

bflad commented Dec 19, 2022

Hi @k-yomo 👋 Thank you for raising this feature request.

While it technically would not be difficult to implement this validator in this Go module, an intention of terraform-plugin-framework's extensible type system is to allow provider developers, or the ecosystem at large, to create custom types that can cover specific use cases. Otherwise, this Go module could wind up trying to cover an extremely broad area of all possible string encodings, formats, etc. which is unmaintainable for one project.

Ideally a custom JSON string type with validation baked into it would be created rather than requiring provider developers to separately implement the JSON validation. Future iterations on that concept would help handle syntactical versus semantic equality, which will help prevent Terraform errors or reported drift in cases where inconsequential whitespace differences can occur. We are hoping to have an initial prototype of this done early next month.

@bflad bflad self-assigned this Dec 19, 2022
@k-yomo
Copy link
Author

k-yomo commented Dec 20, 2022

@bflad

Ideally a custom JSON string type with validation baked into it would be created rather than requiring provider developers to separately implement the JSON validation. Future iterations on that concept would help handle syntactical versus semantic equality, which will help prevent Terraform errors or reported drift in cases where inconsequential whitespace differences can occur. We are hoping to have an initial prototype of this done early next month.

Thank you for the comment! It sounds great and can't wait it!!

@bflad
Copy link
Contributor

bflad commented Aug 3, 2023

A new github.com/hashicorp/terraform-plugin-framework-jsontypes Go module is now available with a custom type implementation for JSON strings. The types there perform JSON validation automatically and the normalized type supports ignoring differences in whitespace and property ordering (per the JSON specification). If you can, please give it a try and let us know how it goes. If you would like additional documentation on using custom types, please refer to the custom types documentation. Thanks so much.

@bflad bflad closed this as completed Aug 3, 2023
@github-actions
Copy link

github-actions bot commented Sep 3, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants