Skip to content

Instantly share code, notes, and snippets.

@EdwardGoomba
Created September 7, 2020 17:07
Show Gist options
  • Save EdwardGoomba/df2bb252c0cc91f7a479c43ac7edc67b to your computer and use it in GitHub Desktop.
Save EdwardGoomba/df2bb252c0cc91f7a479c43ac7edc67b to your computer and use it in GitHub Desktop.
Format and Import Content into Sanity

Format and Import Content into Sanity

The following is a quick guide on how to format json data into ndjson and import the resulting data into sanity studio using the sanity cli.

Sanity

Sanity is a structured content platform that is incredibly fast and flexible.

NDJSON

NDJSON is a convenient format for storing or streaming structured data that may be processed one record at a time.

  • Each line is a valid JSON value
  • Line separator is ‘\n’

1. Convert JSON to NDJSON

Get jq here: https://stedolan.github.io/jq/

cat test.json | jq -c '.[]' > test.ndjson

User the above code to convert and save JSON files in NDJSON format.

2. Use Sanity CLI to import content

Note: You need to have the sanity CLI installed prior to running command.

sanity dataset import <file.ndjson> <targetDataset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment