Settings

Theme

Ask HN: Have you found a fulfilling way to handle multi-line text with JSON?

1 points by seph-reed a month ago · 1 comment · 1 min read


JSON doesn't like new-lines in human readable formats (ie, anything but \n). Multiple times a year, I will find myself forgetting this, pasting in some raw text, and seeing that little red squiggly line that means I fucked up.

Depending on scenario, I might just make a string literal object and avoid json all together. Or maybe I have to find and replace newlines for \n. Or maybe I try a different spec. But it always feels unfulfilling.

Has anyone found something that feels good?

turtleyacht a month ago

This works with Ruby heredoc:

  $ irb
  query = <<-json
  { "s": "a string with
  newlines"
  }
  json
  => "{ \"s\": \"a string with\nnewlines\"\n}\n"

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection