Hi Text Blaze Community,
I’ve been working on a snippet to parse JSON (created from a LLM chat window) from my clipboard and automatically fill fields in Apple Mail. However, I keep encountering errors, and I’m hoping someone can help me troubleshoot. Here’s what I’ve tried so far:
Context:
I want to copy JSON like the following example to my clipboard and use a Text Blaze snippet to fill in the "To," "Subject," and "Body" fields in Apple Mail:
{
"email": "example@example.com",
"subject": "Follow-up on Project Proposal",
"body": "Dear Team,\n\nI hope this email finds you well. I wanted to follow up on our discussion regarding the project proposal. Please let me know if you need any additional information.\n\nBest regards,\n[Your Name]"
}
Steps I’ve Tried:
- Basic Parsing Attempt
Here’s the snippet I initially wrote:
{=email_data = fromjson({clipboard})}
To: {=email_data.email}{key: tab}
Subject: {=email_data.subject}{key: tab}
Body: {=email_data.body}
Issue: I get an error saying Unknown name "email_data"
.
- Adding Validation with
{if}
I updated the snippet to validate the clipboard content before parsing:
{if: testregex({clipboard}, "^\{.*\}$")}
{=email_data = fromjson({clipboard})}
To: {=email_data.email}{key: tab}
Subject: {=email_data.subject}{key: tab}
Body: {=email_data.body}
{else}
[Error: Invalid JSON structure in clipboard]
{endif}
Issues Encountered:
-
"Invalid formula for
{if}
" – The condition doesn’t seem to work properly. -
"Unknown name 'email_data'" – Even after validation, the variable isn’t recognized.
-
Error Handling Attempt
I tried adding more robust error handling:
{if: testregex({clipboard}, "^\{.*\}$")}
{=email_data = fromjson({clipboard})}
{if: typeof(email_data) != "list"}
To: {=email_data.email}{key: tab}
Subject: {=email_data.subject}{key: tab}
Body: {=email_data.body}
{else}
[Error: Invalid JSON structure]
{endif}
{else}
[Error: No JSON found in clipboard]
{endif}
Issues Encountered:
- The
{typeof}
validation doesn’t seem to work as expected. - The regex validation fails with an error about "lone quantifier brackets."
- How can I properly initialize and use variables like
email_data
after parsing JSON? - What’s the correct way to validate clipboard content before parsing it as JSON?
- Are there better approaches for handling errors or ensuring smooth parsing?
- I’ve verified that my JSON is valid using external tools like JSONLint.
- My Text Blaze version is up-to-date.
- I’ve tried using
extractregex()
for simpler parsing but couldn’t get it to work with nested fields.
Any advice or guidance would be greatly appreciated!