chucker icon indicating copy to clipboard operation
chucker copied to clipboard

JSON Request/Response Body Syntax Color Highlighting

Open seanghay opened this issue 4 years ago • 13 comments

:warning: Is your feature request related to a problem? Please describe

image

:bulb: Describe the solution you'd like

:bar_chart: Describe alternatives you've considered

:page_facing_up: Additional context

:raising_hand: Do you want to develop this feature yourself?

  • [x] Yes
  • [ ] No

seanghay avatar Apr 14 '20 03:04 seanghay

Would it be nice if we can display JSON like this? image

seanghay avatar Apr 14 '20 06:04 seanghay

Sounds like a valuable feature @seanghay. Just a couple of things to keep in mind:

  • I'd love to make sure that the color scheme is configurable has good contrast ratio both in the light and the dark background.
  • In this page there is also a "search" feature that will highlight the found occurrences of a string you search. Please make sure that it still works correctly.
  • Performance is really important in this page. We already worked on the body page and refactored to use a RecyclerView with one entry per line. Please make sure that adding a syntax highlighting won't impact the performance of this page significantly.

cortinico avatar Apr 14 '20 23:04 cortinico

@cortinico Is is slow to set everything into a single TextView rather than using RecyclerView to render each line?

seanghay avatar Apr 15 '20 06:04 seanghay

Regarding search - there will be my PR this week changing it a little bit. Just be aware.

@seanghay As to putting everything into one TextView - yes, it is slow. On some big responses it caused ANR errors. This is why we switched to RecyclerView.

vbuberen avatar Apr 15 '20 06:04 vbuberen

Thanks @vbuberen. I will start looking into it and hopefully will open a pull request soon.

seanghay avatar Apr 15 '20 06:04 seanghay

Would like to to give a heads up on this issue - I started to play around with MergeAdapter, which looks a great thing for lots of improvements, including this feature request. While it is still in alpha we can't let it go into the library, but I will open a draft PR to have it visible and maybe inspire someone.

vbuberen avatar May 04 '20 07:05 vbuberen

Hi @seanghay, how is it going your working? It's a really good feature request, if you want I can help you for delivering the feature.

mertceyhan avatar Oct 05 '20 21:10 mertceyhan

Hi @seanghay, how is it going your working? It's a really good feature request, if you want I can help you for delivering the feature.

Hi @mertceyhan! I haven't worked on it yet, if you can help that would be great.

seanghay avatar Oct 06 '20 10:10 seanghay

It's not looking possible when using with as a recyclerView item. Because deciding it's a key or value in a single line is so hard. Has it really different performance when we use recyclerView or single textView? @vbuberen @cortinico

mertceyhan avatar Oct 06 '20 20:10 mertceyhan

It's not looking possible when using with as a recyclerView item. Because deciding it's a key or value in a single line is so hard. Has it really different performance when we use recyclerView or single textView? @vbuberen @cortinico

I think you can create a SpannableString with Syntax Highlighting before splitting it into lines, so each line is a SpannableString which keeps its colors, and then it will render the same as using a TextView.

The challenging part for me is to tokenize the JSON string and highlight all syntaxes.

seanghay avatar Oct 07 '20 10:10 seanghay

@mertceyhan We switched from TextView, because we had an issue reported about poor performance on some big responses. In general, I believe that current RecyclerView implementation is the best solution at the moment till we switch to Jetpack Compose (when it reaches some stable state).

Agree with your point on trying to distinguish key and value. This is what stopped us and other contributors so far, I guess. But I believe that there is a solution for future. Since we are going to introduce some breaking changes in 4.x release we also have plans on redesigning database entities to have separate Transaction, Request and Response models. And in these redesigned models I thought we could change the way how we store the payload to not have just a big String there.

So I would suggest to not spend time on this issue at the moment till we present something more suitable for such customizations.

vbuberen avatar Oct 07 '20 11:10 vbuberen

@vbuberen Thanks for the explanation.

mertceyhan avatar Oct 07 '20 14:10 mertceyhan

I just fork to use webview and use function of https://highlightjs.org/ but not tested heavily; https://github.com/esabook/chucker

esabook avatar Dec 20 '21 16:12 esabook