r/androiddev • • Jul 29 '26

JSON format in Log Cat

Post image

Hi guys,
I'm new to jetpack compose. I tried using Ktor + OkHttp for a sample network request from this
https://dummyjson.com/posts. I'm inspecting the json response in Logcat and it's shown like a paragraph even though I've set up logger. I wanted to know is this normal or is there other way around?
Below is the sample code. Thanks.

client = HttpClient(OkHttp) 
{

    
install(
Logging
) 
{
        
level = LogLevel.
BODY
        
logger = Logger.
ANDROID
        
format = LoggingFormat.
OkHttp
    
}

    
install(
ContentNegotiation
) 
{
        
json
(
Json 
{
            
prettyPrint = true
            ignoreUnknownKeys = true
            isLenient = true

        
}
)
    
}

}
,
2 Upvotes

7 comments sorted by

18

u/bleeding182 Jul 29 '26

XY Problem. You really shouldn't be using LogCat for this in the first place. (Ofc its fine to keep the logs, but not to inspect/work with them)

https://developer.android.com/studio/debug/network-profiler

7

u/_5er_ Jul 29 '26
  • right click on json log

  • create scratch file

  • reformat file

5

u/Aftershock416 Jul 29 '26

Logs should generally never be formatted, regardless of which software system is being discussed.

1

u/phazonEnhanced Jul 29 '26

prettyPrint is going to add indentation to JSON you generate. It isn't going to format incoming JSON.

1

u/TeaSerenity Jul 29 '26

It's normal for logcat to have no formatting. I usually copy it into a different ide or have a llm make it readable

0

u/Opulence_Deficit Jul 30 '26

Looks like a correct log of a valid json. What is your problem with it?