anyboxhq / everything-okjson

Submit your feature requests or bug reports here.
https://docs.okjson.app
Apache License 2.0
10 stars 0 forks source link

Support for loading ndjson content from clipboard #31

Closed shames0 closed 10 months ago

shames0 commented 11 months ago

First of all, thanks for the great app! I use it every-day and I find it to be reasonably priced, user friendly, and more performant than other tools I've tried. I've been recommending it to all my coworkers.

Is your feature request related to a problem? Please describe. I appreciate the ability to open *.ndjson files, but I find myself more often trying to paste ndjson content into a new OK JSON tab or window. Whenever I do this OK JSON doesn't recognize the content as valid. I get the following message:

image

Describe the solution you'd like I'd appreciate being able to paste ndjson content (cmd+v) into an OK JSON window just as I can paste normal JSON content.

Describe alternatives you've considered My workaround for this right now is basically the following:

pbpaste > foo.ndjson
jq -s '.' foo.ndjson | pbcopy
rm foo.ndjson

# -- go to OK JSON and paste what was copied

Additionally, there have been regular cases for me where I have been unable to open files with ndjson content seemingly due to logic around the file extension. For example, I'll get files with well-formed ndjson content in any of the following extensions: .jl, .json, .txt. When I try to open these with OK JSON I get a "failed to parse string" message. In order to open these files I have to rename them to have the .ndjson, or .jsonl extension. Enabling this proposed feature to be able to paste ndjson content into OK JSON would help to alleviate this inconvenience.

francisfeng commented 11 months ago

Did you try turning on “Repair mode” (powered by jsonrepair, which I don’t think would contaminate the original info) in “Settings → General”? It should work.

Alternatively you can create a custom script in OK JSON to convert ndjson string to normal JSON string first. The internal conversion in OK JSON is quite simple:

public func convertNDJSONToJSON(_ string: String) -> String {
  let lines = string.components(separatedBy: .newlines).filter{!$0.isEmpty}
  let result = "[" + lines.joined(separator: ",") + "]"
  return result
}

For more info on custom scripts, go to https://docs.okjson.app.

If you don’t want to use custom scripts in OK JSON nor the Repair mode, you can also somehow automate this with the script you already have. OK JSON has a URL Scheme that it’s well suited for this situation: okjson://paste.

In terminal:

open "okjson://paste"

Regarding the file extensions, .jl is recognized as source code files of the Julia language by macOS. And json file is really a JSON file. Treating them as ndjson is wrong in this regard.

Let me know if you have any other questions.

shames0 commented 11 months ago

@francisfeng Great response. Thanks for the feedback and ideas! I've neglected the custom scripts feature completely. I'll give that a try, as well as the "Repair mode".

Thanks again!