Comments (3)
Hi @johakoch! Thanks for sharing this feature request.
While I can see that this extra escaping is a cosmetic irritant, it's still a valid serialization of the input data and so I feel disinclined to cause potential churn by changing the default behavior, or to complicate the API by making it configurable.
Can you say more about why it matters for your use-case exactly how the JSON data is encoded, assuming that it always generates valid JSON? When I wrote this I did it on the assumption that JSON encoded cty
objects are primarily for machine consumption and so human readability was not a priority. That is also why it always generates minified JSON, for example, with no option to configure that either.
from go-cty.
Hi @apparentlymart .
For Couper we use hcl as our configuration language which also allows to compose some individual payloads via variables either as part of a response or request json_body
. This is enabled with converting the related payload to cty and vice versa (hcl evaluation). At this point the user does not expect a modification of its content which happens due to the json.Marshal default behaviour.
A simple example which has been solved in our fork:
# simple server endpoint which reflects the client json payload
server {
endpoint "/json" {
response {
json_body = request.json_body
}
}
}
curl -X POST -H "Content-Type: application/json" -d '{ "prop": "<p>html</p>" }' http://localhost:8080/json
{"prop":"\u003cp\u003ehtml\u003c/p\u003e"}
An additional use-case would be the proxy case which connects a (legacy?) system which may also send unescaped data and we want to read/sniff into them for whatever reasons which may prevent us to pipe the body.
So it may solve just our use-case but we could think about a better integration of an possible opt out for html escaping if you give us a thump up ;)
from go-cty.
Related Issues (20)
- Feature Request: Pretty-print option for JSONEncodeFunc HOT 1
- function/stdlib: TestCSVDecode fails with Go tip HOT 3
- How can I get Value as interface HOT 4
- third param for `lookup` function is not optional HOT 2
- Extend FormatDateFunc to support seconds since Unix Epoch HOT 4
- Consider using "hash/maphash" for set element hashing HOT 1
- 1.11.0 causes errors with //go:generate packer-sdc mapstructure-to-hcl2 HOT 1
- hashicorp/packer-plugin-sdk incompatible with zclconf/go-cty v1.11.0 HOT 4
- TestFormatDate fails with upcoming Go 1.20 release HOT 5
- Add support for decoding into structs with a custom tag HOT 1
- Nested go struct to cty value fails HOT 1
- Proposal: JSON serialization of `cty.Path` HOT 3
- stdlib: SetProductFunc doesn't seem to handle refinements quite right HOT 2
- How to convert cty.Value of unknown type into `interface{}` HOT 2
- cty.StringVal always doubles $ in `${}` output HOT 2
- Parse string into cty type HOT 1
- cty.StringVal always doubles $ in ${} output Pt2 HOT 1
- adding jsonencode() block into a generated terraform file using golang cty HOT 2
- Encoding values with custom function (terraform provider) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-cty.