Print pretty JSON in Swift 5
When dealing with REST APIs and JSON data in iOS it can be very useful to be able to see the data in raw string format. With this small extension you can print JSON data as an optional string from a Data
object:
extension Data { var prettyJSON: String? { guard let object = try? JSONSerialization.jsonObject(with: self, options: []), let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]) else { return nil } return String(data: data, encoding: .utf8) } }
Now, consider the following struct
:
struct Person: Codable { var name: String var age: Float }
And then lets create an array of people and encode it into data
:
let people = [ Person(name: "Gunther", age: 24.5), Person(name: "Viktor", age: 33) ] let data = try? JSONEncoder().encode(people)
Now we can use the extension and print the data in pretty json:
print(data?.prettyJSON ?? "") /* [ { "name" : "Gunther", "age" : 24.5 }, { "name" : "Viktor", "age" : 33 } ] */
189 comments on “Print pretty JSON in Swift 5”
Comments are closed.
Pingback: cialis promise program
Pingback: generic viagra for sale cheap
Pingback: centurion laboratories tadalafil
Pingback: cheap cialis with dapoxetine
Pingback: viagra gel in india
Pingback: tadalafil tablets usp
Pingback: us online pharmacy hydrocodone
Pingback: sildenafil tablets 100mg online
Pingback: buy viagra online cheap india
Pingback: sildenafil tablets 100mg price
Pingback: sildenafil tablets 100mg buy
Pingback: where can you buy viagra over the counter in uk
Pingback: viagra india price
Pingback: cialis from canadian pharmacy registerd
Pingback: iron dragon tadalafil
Pingback: cialis manufacturer coupon 2018
Pingback: cialis wikipedia
Pingback: metronidazole giardiasis
Pingback: gabapentin prodrug
Pingback: does sulfamethoxazole affect birth control
Pingback: tamoxifen distribution
Pingback: lyrica for sciatica reviews
Pingback: rapivir valacyclovir
Pingback: metformin farting
Pingback: furosemide syringes
Pingback: lisinopril hct2
Pingback: rybelsus 14mg 90 comprimidos
Pingback: jardiance semaglutide
Pingback: semaglutide headache reddit
Pingback: max dose of zoloft
Pingback: nizole metronidazole
Pingback: keflex 3 times a day how far apart
Pingback: sildenafil 5 mg tablet
Pingback: duloxetine addiction
Pingback: cephalexin and metronidazole taken together
Pingback: can you drink alcohol while on fluoxetine
Pingback: lexapro insomnia
Pingback: cymbalta for degenerative disc disease
Pingback: gabapentin diverticulitis
Pingback: lamotrigine and escitalopram
Pingback: is ciprofloxacin a strong antibiotic?
Pingback: cefdinir vs cephalexin
Pingback: antibiotic bactrim
Pingback: bactrim and coumadin
Pingback: amoxicillin for bacterial vaginosis
Pingback: maximum flomax dosage
Pingback: depakote overdose
Pingback: generic name for flexeril
Pingback: diltiazem blood pressure
Pingback: how much in contrave
Pingback: citalopram engorda o adelgaza
Pingback: ezetimibe simvastatin sharp
Pingback: diclofenac sodium gel
Pingback: cozaar manufacturer
Pingback: augmentin for diverticulitis
Pingback: is effexor a controlled substance
Pingback: ddavp nasal spray von willebrand
Pingback: aripiprazole interactions
Pingback: is advil aspirin
Pingback: amitriptyline 10 mg para que sirve
Pingback: alternatives to allopurinol
Pingback: celecoxib vs.celebrex
Pingback: buspar weight loss
Pingback: celebrex and sulfa
Pingback: celexa alcohol
Pingback: ashwagandha health benefits
Pingback: augmentin yeast infection
Pingback: lamictal vs abilify
Pingback: repaglinide uv absorbance
Pingback: obat acarbose.pdf
Pingback: remeron drugs
Pingback: protonix pricing
Pingback: what are the side effects of semaglutide
Pingback: actos bochornosos
Pingback: can you take robaxin and ibuprofen together
Pingback: synthroid eutirox
Pingback: tizanidine is it a narcotic
Pingback: half life of venlafaxine
Pingback: tamsulosin hypotension
Pingback: how long does the drug voltaren stay in your system
Pingback: ivermectin 0.5% brand name
Pingback: sitagliptin januvia 100 mg
Pingback: spironolactone 100 mg used for
Pingback: vicodin online pharmacy no prescription
Pingback: levitra online pharmacy
Pingback: generic sildenafil
Pingback: sildenafil 20 mg side effects
Pingback: tadalafil / tadacip 20 dosage
Pingback: cialis vs viagra vs levitra
Pingback: inhouse pharmacy motilium
Pingback: cialis online pills
Pingback: vardenafil troches
Pingback: stromectol 12mg online
Pingback: ivermectin pills
Pingback: ivermectin 400 mg
Pingback: ivermectin 2%
Pingback: best place to buy liquid tadalafil
Pingback: ivermectin lotion cost
Pingback: cialis tadalafil patent
Pingback: order viagra online australia
Pingback: stromectol for sale
Pingback: vardenafil wikipedia
Pingback: price of sildenafil citrate
Pingback: what does amoxicillin treat
Pingback: can i take zoloft in the morning and trazodone at night
Pingback: generic name for lyrica
Pingback: how long does lisinopril take to work
Pingback: doxycycline classification
Pingback: metformin weight loss dosage
Pingback: what is cephalexin used for in dogs
Pingback: is keflex a cephalosporin
Pingback: valtrex over the counter cvs
Pingback: travelers diarrhea cipro
Pingback: about provigil
Pingback: nolvadex pct for sale
Pingback: online levitra prescription
Pingback: what happens if a woman takes tadalafil
Pingback: trusted overseas pharmacies
Pingback: viagra dosage
Pingback: vardenafil ed il tadalafil
Pingback: how long does it take sildenafil to work
Pingback: how to reduce side effects of sildenafil
Pingback: sildenafil oral jelly 100mg kamagra
Pingback: viagra vs sildenafil
Pingback: what happens if you take expired sildenafil
Pingback: buy levitra 5mg
Pingback: can you mix cialis and viagra
Pingback: tadalafil when to take
Pingback: levitra half life
Pingback: top 10 pharmacies in india
Pingback: order levitra pills
Pingback: what is the difference between sildenafil and tadalafil
Pingback: order generic levitra
Pingback: tadalafil or sildenafil which is better
Pingback: tretinoin cream online pharmacy
Pingback: online medicine order discount
Pingback: vardenafil hcl 20mg tab reviews
Pingback: sildenafil directions
Pingback: best online pharmacy uk viagra
Pingback: is viagra or cialis better
Pingback: internet pharmacy mexico
Pingback: sublingual sildenafil
Pingback: can you cut 20 mg tadalafil in half
Pingback: levitra reviews vardenafil
Pingback: tadalafil canadian pharmacy
Pingback: escitalopram generic pharmacy
Pingback: oxycodone mexico pharmacy
Pingback: online pharmacy flovent inhaler
Pingback: inducible clindamycin resistance in staphylococcus aureus isolated from nursing and pharmacy students
Pingback: tadalafil drug interactions
Pingback: legitimate online pharmacy xanax
Pingback: difference between sildenafil and tadalafil
Pingback: sulfasalazine discussion board
Pingback: neurontin medication
Pingback: fabrica clozaril voltaren tegretol diovan
Pingback: etodolac can get you high
Pingback: can i give my toddler infant motrin
Pingback: hydrocodone gabapentin
Pingback: pastillas celebra celecoxib
Pingback: celebrex support group
Pingback: can i take ibuprofen with benylin
Pingback: carbamazepine in trigeminal neuralgia
Pingback: indomethacin muscle spasms
Pingback: colofac ibs mebeverine hydrochloride
Pingback: can i take tylenol with diclofenac
Pingback: cilostazol jp
Pingback: buy pyridostigmine without prescription
Pingback: mestinon and pots syndrome
Pingback: amitriptyline and prozac
Pingback: tramadol and elavil
Pingback: drug interactions celexa and imitrex
Pingback: google baclofen
Pingback: azathioprine en griep
Pingback: meloxicam pain relief
Pingback: drinking alcohol while taking mobic
Pingback: lioresal half life
Pingback: can imuran cause anemia
Pingback: isordil vs imdur
Pingback: sumatriptan in spanish
Pingback: wie nimmt man maxalt lingua
Pingback: rizatriptan sulfa allergy
Pingback: quais os medicamentos que contem piroxicam
Pingback: how to get cheap ketorolac pills
Pingback: tizanidine nerve pain
Pingback: zanaflex vs skelaxin
Pingback: artane com cerveja
Pingback: cost of generic toradol without a prescription
Pingback: how to get prescription for periactin
Pingback: cyproheptadine pediatric dosing