Skip to content

Instantly share code, notes, and snippets.

@molsonkiko
molsonkiko / pyquery.py
Created June 21, 2023 23:12
pyquery (tool for low-code data conversion with PythonScript in Notepad++)
'''
By Mark J. Olson, June 2023
Simple tool for querying CSVs, JSON, and tabular XML files with Python list comprehensions, etc.
USAGE
1. Download PythonScript (see REFERENCES 1 below).
Put it in your Notepad++ installation's plugins folder.
2. Download this file and put it in %AppData%/Roaming/Notepad++/plugins/config/PythonScript/scripts
3. Go to PythonScript plugin from the main menu, choose the Configuration option,
and add this script to PythonScript's main toolbar.
4. Add a keyboard shortcut for calling the script.
@molsonkiko
molsonkiko / merge_files_by_line.py
Last active September 1, 2023 21:07
Merge files by line (Notepad++ PythonScript script)
# -*- coding: utf-8 -*-
# reference: https://community.notepad-plus-plus.org/topic/24872/is-there-any-alternative-to-merge-files-in-one-plugin/7?_=1693515221904
# installation guide: https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript
from __future__ import print_function
import os
import re
from Npp import *
__version__ = '0.2.0'
@molsonkiko
molsonkiko / dont_parse_json_with_regex_FAQ.md
Created January 3, 2024 15:56
don't parse JSON with regex FAQ (NPP community forum)

You are likely reading this FAQ because you are trying to use regular expressions to work with JSON, and someone wants to explain why this is a bad idea to you. And it is a very bad idea to parse JSON with regular expressions, as you may have already discovered at the cost of hours of frustration and dead-ends. A normal programming language (e.g., Python, JavaScript) is the proper way to work with JSON.

TL;DR: OK, I believe you. I shouldn't use regex to search in or edit JSON. What can I use instead?

  • Python
    • Overview: Python is an easy-to-learn language, and its json module makes it easy to work with JSON.
    • Plugins: In addition, the PythonScript plugin allows you to run Python scripts inside of Notepad++.
    • For example, here is how to parse the current document as JSON, and pretty-print it:
    # Npp gives us access to the editor com