Skip to content

Output JSON Object wrapped in Array #1877

@gil--

Description

@gil--

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
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions