Hello friends,
Are there any example of configuring Netlify CMS to store content page content in JSON files instead of YML?
Many thanks
Hello friends,
Are there any example of configuring Netlify CMS to store content page content in JSON files instead of YML?
Many thanks
Hi there - Netlify CMS currently supports markdown, yaml, json, and toml. Editing json files works the same way that editing yaml files works. Have you tried and run into any issues?
You can find all available configuration settings for data types here: Configuration Options | Netlify CMS | Open-Source Content Management System
@erquhart or @tomrutgers Could you provide an example of what that setup should look like within the Config? Iāve built my navigation with a JSON file and have tried to point to it with:
- name: "navigation"
label: "Navigation"
files:
- file: "src/data/navigation.json"
label: "Navigation"
name: "navigation"
extension: "json"
format: "json"
editor:
preview: false
fields:
- { name: body, label: Body, widget: code }
The fields doesnāt seem right, but I get an error if I donāt supply one. Within the CMS, the current JSON content wonāt load and I just get the body code editor in the CMS.
The extension
and format
properties belong to the collection, you canāt set it on a per file basis when using a file collection:
- name: "settings"
label: "Settings"
extension: "json"
editor:
preview: false
files:
- file: "src/data/navigation.json"
label: "Navigation"
name: "navigation"
fields:
- { name: body, label: Body, widget: code }
Hmm, I have it setup exactly how you sent it (minus the empty lines, do those matter?) and itās still coming up empty. Iām positive the file has content, and all of my other collections / files are prepopulating.
The empty lines do not matter, thatās just a personal preference. Are your files pushed to Git? If you access the CMS locally, it will still look for your content on Github.
If you can share your repo, Iād more than happy to take a look!
Ah now I get it. Youāre trying to edit the entire jsonās body with a code widget. Unfortunately the body
name only works as a body with markdown. I think youāll have to recreate the navigation.json
file by using widgets:
fields:
- name: overview
label: Overview
widget: list
fields:
- name: links
label: Links
widget: list
fields:
- {name: title}
- {name: url}
...
@erez Do you have any idea if editing the contents of a json file from a code widget is possible in some other way?
Thanks for the mention @tomrutgers, you can use the code widget to edit an entire json file, it requires a bit of restructuring of the current data:
Thanks a ton for your help!!
Hmm looking into this, I think itās worth noting that itās kind of a bummer that it has to be formatted this way to edit. This makes it very hard to manage in code, which means I have to decide if the file is managed within the CMS or within the code. I was hoping the CMS could just pull the file exactly as it is, just to expose it within the CMS and allow someone to make changes without needing Github.
You can, but then you have to recreate its structure in config.yml instead of using the code widget.
hi can we have single json file rather than each entry to the collection creating new json files .
Hey @crimzonarc,
If Iām understanding correctly, I believe this is a feature request-- possibly the one being discussed here?
Feel free to chime in there to voice your support, or let us know here if you have followup questions!
@sdzaveri Agreed. I would like to automatically generate content based on data that is produced by a different application (my example is Dialogflow). Their json data contains a lot of information that I donāt need, lacks a templateKey, and is split into multiple files that are identified as parts of a whole based on prefixes/suffixes.
I may, unfortunately, need to seek a solution that is far more dynamic than Netlify.
Fortunately, you can use any CMS with Netlifyās web service
This works very well! Even without the ugly ārestructuringā, @sdzaveri.
This:
collections:
- name: "terminkalender" # Used in routes, e.g., /admin/collections/blog
label: "Terminkalender" # Used in the UI
media_folder: /content/yoga_meditation/termine/timetable/images
public_folder: /
create: false # Allow users to create new documents in this collection
delete: false
extension: json
format: json
editor:
preview: true
files:
- label: "Termine"
name: "termine"
file: "/content/yoga_meditation/termine/timetable/timetables_day.json"
fields:
- name: items
label: Kalendereintrag
widget: list
fields:
- name: day
label: Tag
required: false
widget: "select"
options:
["monday", "tuesday", "wednesday", "thursday", "friday"]
- name: name
label: Titel
widget: string
- name: image
label: Bild
required: false
widget: image
- name: start_time
label: Start
widget: string
- name: end_time
label: Ende
widget: string
- name: color
hint: "von 1-3 wird die Farbe immer satter, 4 ist grau."
label: Farbe
widget: "select"
options: ["1", "2", "3", "4"]
- name: description
label: Beschreibung
widget: text
results in:
{
"items": [
{
"day": "tuesday",
"name": "sadsdqwdqwqdqw",
"image": "/yoga.jpg",
"start_time": "11:20",
"end_time": "15:40",
"color": "1",
"description": "ssdqwqdwdqwqdq"
}, ā¦
]
}
What a pain in theā¦ but finally it works! THANK YOU!
Thank you! This really help me out with my use case, and I was able to fix my issue!
Part of my config.yml
- name: 'trackers'
label: 'Trackers'
label_singular: 'Tracker'
extension: json
format: json
create: false
editor:
preview: false
files:
- label: "Solar Tracker"
name: "solar-tracker"
file: "_data/national-goals/solar-performance-tracker.json"
fields:
- label: 'States'
name: 'tracker'
widget: 'list'
allow_add: false
collapsed: true
fields:
- { name: 'state' }
- { name: 'national_contribution' }
- { name: 'state_target' }
- { name: 'state_achieved' }
- { name: 'state_percentage' }
save my json like this.
{
"tracker": [
{
"state": "state name",
"national_contribution": "0.03",
"state_target": 27,
"state_achieved": "29.91",
"state_percentage": "110.77"
},
{
"state": "state name",
"national_contribution": "4.52",
"state_target": 9834,
"state_achieved": "4524.72",
"state_percentage": "46.01"
},
{
"state": "state name",
"national_contribution": "0.01",
"state_target": 39,
"state_achieved": "11.52",
"state_percentage": "29.53"
}
]
}