Android Question [SOLVED] Presenting single line JSON response as pretty

JackKirk

Well-Known Member
Licensed User
Longtime User
I'm playing around with Http that produces a single line JSON response such as:

{"FaceRecords":[{"Face":{"BoundingBox":{"Height":0.1922222226858139,"Left":0.25889328122138977,"Top":0.23555555939674377,"Width":0.34189721941947937},"Confidence":99.97904205322266,"FaceId":"dd15f62b-3548-5a0a-b26e-8daf3953a34c","ImageId":"3e59342e-e124-5943-9f65-c9287f8f7f22"},"FaceDetail":{"BoundingBox":{"Height":0.1922222226858139,"Left":0.25889328122138977,"Top":0.23555555939674377,"Width":0.34189721941947937},"Confidence":99.97904205322266,"Landmarks":[{"Type":"eyeLeft","X":0.37268081307411194,"Y":0.31961020827293396},{"Type":"eyeRight","X":0.47631895542144775,"Y":0.30841925740242004},{"Type":"nose","X":0.44546324014663696,"Y":0.34176579117774963},{"Type":"mouthLeft","X":0.3984130918979645,"Y":0.38350239396095276},{"Type":"mouthRight","X":0.49762099981307983,"Y":0.3726522624492645}],"Pose":{"Pitch":9.297144889831543,"Roll":-11.852437973022461,"Yaw":7.903125286102295},"Quality":{"Brightness":49.09339904785156,"Sharpness":99.47134399414062}}}]}

I have created the following code to log it as pretty JSON:
B4X:
'Convert single line JSON response to a map
Private JSON_parser As JSONParser
Private JSON_map As Map
JSON_parser.Initialize(Job.GetString)
JSON_map = JSON_parser.NextObject
          
'Convert map to a multi-line JSON response
Private JSON_response As JSONGenerator
JSON_response.Initialize(JSON_map)
              
'Log multi-line JSON resonse
Log(JSON_response.ToPrettyString(4))
which seems messy - is there a prettier way to do it?
 
Top