clojuretext-editor

How to edit edn file?


I have an edn file created from a clojure app. I'd like to edit the file directly to modify some values, but don't know how to do it easily. I know that I can edit it in a text editor like sublime but the whole file is on the first line with no line breaks. Is there some tool to break it down into fields, records, or key value pairs to make it easier, without having to learn clojure?

More detail: The app in question is Logseq. It maintains a file of all pages with a creation date and update date for each. The creation date is not correct, so I was going to edit it directly. Since I don't know clojure then I can't use pprint. In sublime it is listed as:

[{:block/name "05-24-2021", :block/created-at 1621814400000, :block/updated-at 1621814400000} {:block/name "06-04-2021", :block/created-at 1622764800000, :block/updated-at 1622764800000} {:block/name "openings study", :block/created-at 1627400166344, :block/updated-at 1627400166344} {:block/name "progressive summarization", :block/created-at 1627587170901, :block/updated-at 1627587770818} 

What I'd like it to look like for easier editing:

[{
:block/name "05-24-2021", :block/created-at 1621814400000, :block/updated-at 1621814400000} 
{:block/name "06-04-2021", :block/created-at 1622764800000, :block/updated-at 1622764800000} 
{:block/name "openings study", :block/created-at 1627400166344, :block/updated-at 1627400166344} 
{:block/name "progressive summarization", :block/created-at 1627587170901, :block/updated-at 1627587770818} 
etc.

Solution

  • Assuming that you have boot installed in your PATH, you can pipe your code through the following script:

    #!/usr/bin/env boot
    (require '[clojure.edn :as edn]
             '[clojure.pprint :refer [pprint]])
    
    (defn -main [& args] (pprint (edn/read *in*)))
    

    ...as in (if the above is saved as pprint-edn):

    pprint-edn <unformatted.edn >formatted.edn