プロジェクト

全般

プロフィール

【2025年版】 Amazon Bedrock AgentCoreまとめ資料を公開します!

Wiki

const prevDiv = target.locator('xpath=preceding-sibling::div[1]');
git branch | grep '^  feature/' | sed 's/^  //' | xargs -r git branch -D
git branch | grep '^  feature/'

https://docs.github.com/ja/copilot/concepts/billing/individual-plans

/**
 * 文字列の先頭/末尾に ```json ... ``` のコードブロックがあれば除去し、
 * JSON.parse 可能な "{...}" 形式に整形する関数
 */
export function normalizeJsonString(input: string): string {
  if (!input) return input;

  let text = input.trim();

  // ```json で始まる場合
  if (text.startsWith("```")) {
    // 先頭の ```json または ``` を削除
    text = text.replace(/^```json\s*/i, "").replace(/^```\s*/i, "");

    // 末尾の ``` を削除
    text = text.replace(/\s*```$/, "");
  }

  // JSON部分だけ切り出し(最初の { 〜 最後の })
  const start = text.indexOf("{");
  const end = text.lastIndexOf("}");

  if (start !== -1 && end !== -1 && end > start) {
    text = text.slice(start, end + 1);
  }

  return text.trim();
}

/**
 * 使用例
 */
const raw = `
\`\`\`json
{
  "name": "test",
  "value": 123
}
\`\`\`
`;

const normalized = normalizeJsonString(raw);
const obj = JSON.parse(normalized);

console.log(obj);