Git Product home page Git Product logo

Comments (3)

apparentlymart avatar apparentlymart commented on July 30, 2024

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.

malud avatar malud commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.