M
M
Magus_Education2021-04-18 17:27:42
go
Magus_Education, 2021-04-18 17:27:42

How to display data in JSOn format as strings in golang?

Hello. I'm not sure if the question is correct, but still. I receive data in JSON format that looks like this. 607c40be29fa2302039644.png
I accept this data, process it in a REST api with working CRUD and get this kind of output that I can interact with 607c413090b18329668050.png
. Question: how to make the output as beautiful as it was originally? Thank you in advance.
Code: https://play.golang.org/p/AMNTFim5xXI

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Romses Panagiotis, 2021-04-18
@Magus_Education

Essentially, the output is equal to the input. Except that the input is
an array of objects {id:, userId:, title: body:}
and the output:
an array of objects {ID:, userId:, title: body:}
That is, id -> ID. Well, copy values ​​from one structure to another structure with other fields. When json.Marshalyou get a new array.

how to make the output as beautiful as the original?
This is redundant: for the computer, this only leads to additional overhead.
If a person does not look at "beauty" somewhere, then there is no point. Also, in the browser, DevTools usually has auto-align indentation built in, so this shouldn't be a problem.
In total, the current statement of the problem sounds like a transfusion from empty to empty.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question