Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output JSON Object wrapped in Array #1877

Closed
gil-- opened this issue Nov 14, 2018 · 6 comments
Closed

Output JSON Object wrapped in Array #1877

gil-- opened this issue Nov 14, 2018 · 6 comments

Comments

@gil--
Copy link

gil-- commented Nov 14, 2018

Is it possible to somehow output the JSON object in an array? I tried doing that manually but the array wrapper is removed upon saving fields.

Currently:

{
    "canAdd": true,
    "showBreadcrumbs": true,
    "showSocialSharing": true
}

However, I'm using Netlify-CMS with Gatsby and I'm trying to Query the JSON using gatsby-transformer-json but it seems it requires arrays or strings and not an object. If I wrap the Netlify outputted object in an array it works:

[{
    "canAdd": true,
    "showBreadcrumbs": true,
    "showSocialSharing": true
}]

That does the trick but the array wrapper [] is removed on every save. Without the array wrapper, showBreadcrumbs and showSocialSharing are not query-able:

screen shot 2018-11-13 at 10 16 29 pm

Has anyone tried to import JSON into gatsby before and had better luck? I basically need array instead of key-value.

I ended up querying allFile which allows me to filter on a specific file name such as products.json but it's definitely not ideal. Would prefer just wrapping JSON object in an array for a more simplified graphql query.

query settings {
  allFile (filter: {
    name: { eq: "products" }
  }) {
    edges {
      node {
        childSettings {
          canAdd
        }
      }
    }
  }
}
@erquhart
Copy link
Contributor

Definitely a need, could have sworn we had an issue for this.

@donaldboulton
Copy link

donaldboulton commented Nov 29, 2018

I wish we could use json data sets as I need one for fullCalendar events as a json data set not just a json file.
How to?

Figured it out with:
frontmatter_delimiter: if you have an explicit frontmatter format declared, this option allows you to specify a custom delimiter like ~~~. If you need different beginning and ending delimiters, you can use an array like ["(", ")"].

@erquhart
Copy link
Contributor

erquhart commented Feb 5, 2019

@gil-- I think I misread this initially - you can use the list widget for this, defining fields just as you currently do with the object widget.

@erquhart
Copy link
Contributor

erquhart commented Aug 28, 2019

Hmm not sure what I was thinking on Feb 5, this is definitely not possible. We essentially need field for collections, the same way we have field for the list widget as an alternative to fields.

fields: produces an object, and the name of each configured field becomes a key.
field: produces a list of one or more of the configured field's values - field name is not used.

I still think this issue is a dupe, just can't find the original. Ah well. Adding to radar.

@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@erquhart
Copy link
Contributor

erquhart commented Nov 8, 2019

Finally found it - this is a duplicate of #531, please track there.

@erquhart erquhart closed this as completed Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants