Skip to content

Instantly share code, notes, and snippets.

@afeld
Created September 17, 2018 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afeld/eb091f4ae1267a1c499710b9629246c0 to your computer and use it in GitHub Desktop.
Save afeld/eb091f4ae1267a1c499710b9629246c0 to your computer and use it in GitHub Desktop.
get list of properties from a JSON Schema

Uses jq.

cat schema.json | \
  jq -r '[paths | join(".")] | .[]' | \
  grep 'properties\.\w\+$' | \
  sed 's/properties\.//g'

Example with this file:

$ cat recalls_api_schema_new.json | jq -r '[paths | join(".")] | .[]' | grep 'properties\.\w\+$' | sed 's/properties\.//g'
RecallID
RecallAgency
RecallNumber
RecallDatetime
Description
URL
Title
ConsumerContact
ConsumerContact.entity
ConsumerContact.type
ConsumerContact.value
ConsumerContact.title
LastPublishDate
Product
Product.Name
Product.Description
Product.Model
Product.Type
Product.CategoryID
Product.NumberOfUnits
Inconjunction
Inconjunction.Country
Image
Image.URL
Injury
Injury.Name
Manufacturer
Manufacturer.Name
Manufacturer.CompanyID
ManufacturerCountry
ManufacturerCountry.Country
ProductUPC
ProductUPC.UPC
Hazard
Hazard.Name
Hazard.HazardTypeID
Remedy
Remedy.Name
Remedy.Options
Retailer
Retailer.Name
Retailer.CompanyID
Importer
Importer.Name
Importer.CompanyID
Distributor
Distributor.Name
Distributor.CompanyID
SeverityCategory

There is likely a cleaner way to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment