Node.js script to iterate through json files and make changes. Written to add a field to a Prismic type and populate it programmatically so that users wouldn't have to edit a lot of records. This can be used as the basis for future needs to bulk edit data from Prismic (which is exported as individual json files for each record).
- If you are using this to populate a new Prismic field, make sure you have added that field to your model in Prismic.
- Clone or fork this repo.
- Run
npm install
to get the packages. - Add a "ForEditing" folder (at the same level as the node_modules folder). Place files you wish to edit in the "For Editing" folder.
- Run
node JsonFileIterateAndEdit.js
in the console. - Your files have been edited and you can now re-import them to Prismic.
- Once you're done, you can clear the files out of "For Editing."
This script was written to bulk edit a specific Prismic type of item. The script deletes any documents of a different type since we don't want to edit and upload anything other than the items of the target type.
For future use in bulk edits, simply change as needed. Change the targetPrismicType
variable to target the Prismic type you want to edit, and make edits in the loop to handle whatever edits you need to make. In this case we are slug-ifying the existing title field and adding it as a 'uid' field.