• With issues:
  • Use the search tool before opening a new issue.
  • Please provide source code and commit sha if you found a bug.
  • Review existing issues and provide feedback or react to them.

Description

I have the JOSN data as a []byte generated from another function.

Want to use it directly with IndentedJSON

How to reproduce

    c.IndentedJSON(http.StatusOK, string(Data))

Expectations

"{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[-124.136559,41.464451],[-124.137894,41.4683],[-124.139061,41.472935],[-124.140541,41.477234],...

Actual result

"{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-124.136559,41.464451],[-124.137894,41.4683],[-124.139061,41.472935],[-124.140541,41.477234],

Environment

  • go version: 1.16
  • gin version (or commit ref): latest
  • operating system: macOS M1

Comment From: swarajkumarsingh

  • With issues:

  • Use the search tool before opening a new issue.

  • Please provide source code and commit sha if you found a bug.
  • Review existing issues and provide feedback or react to them.

Description

I have the JOSN data as a []byte generated from another function.

Want to use it directly with IndentedJSON

How to reproduce

c.IndentedJSON(http.StatusOK, string(Data))

Expectations

"{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[-124.136559,41.464451],[-124.137894,41.4683],[-124.139061,41.472935],[-124.140541,41.477234],...

Actual result

"{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-124.136559,41.464451],[-124.137894,41.4683],[-124.139061,41.472935],[-124.140541,41.477234],

Environment

  • go version: 1.16
  • gin version (or commit ref): latest
  • operating system: macOS M1

Greeting thstart

There are two ways to solve this err 1. don't convert the data to a string instead directly pass it to c.IndentedJSON. 2. Use c.JSON(, data)

I guess solution 2 is a good one because c.IndentedJSON is a more CPU-intensive task as it serializes the given struct as pretty JSON (indented + endlines) into the response body. But c.JSON does not and is quick compared to c.IndentedJSON

Comment From: swarajkumarsingh

Greeting thstart

There are two ways to solve this err 1. don't convert the data to a string instead directly pass it to c.IndentedJSON. 2. Use c.JSON(, data)

I guess solution 2 is a good one because c.IndentedJSON is a more CPU-intensive task as it serializes the given struct as pretty JSON (indented + endlines) into the response body. But c.JSON does not and is quick compared to c.IndentedJSON