How to replace keywords in a prismic json document via migration API?

Hi team,
We are trying to replace certain keywords in a Prismic JSON and re-upload it back to Prismic via the migration API. I noticed it would cause problems in paragraphs with links. For example in a paragraph:

`{
   "type":"paragraph",
   "content":{
      "text":"Use this TOOL free plan text converter If you need to convert your copied text to plain text, just paste your text here",
      "spans":[
         {
            "start":9,
            "end":12,
            "type":"hyperlink",
            "data":{
               "url":"https://www.something.com"
            }
         }
      ]
   }
}`  

If I want to replace the keyword instance of `TOOL``` to NEWTOOL, the hyperlink start and end position will also change, which means we need to re-calculate the position of all the links in a paragraph. Is there a better to achieve the similar result?

Thanks,
Patrick

Hey @patrickzsy,

Since the Migration API is still quite new and in beta, we don't have a recommended path for this yet. You might find something helpful in this repository of example scripts:

In the coming months, we'll release more tools for interacting with the Migration API.

Sam

1 Like