Viewing JSON field in workspace

Feature(s) impacted

Workspace

Observed behavior

We have created a smart field that’s a JSON and we also have a model field that’s a JSON as well we were trying to bring this into our workspace but no matter what we try it’s out outputting the JSON.

Is it even possible to show the JSON in the workspace?

Expected behavior

Field outputs JSON

Failure Logs

Context

  • Project name: …
  • Team name: …
  • Environment name: …
  • Agent (forest package) name & version: …
  • Database type: …
  • Recent changes made on your end if any: …

Hey @Zero,

I did not understood at all your issue sorry :sweat_smile:.
Are you trying to display a field inside your json. For example if you have the following json

{
  name: 'test',
  power: 'me'
}

You want to be able to display the name ?

Hi sorry for not being clear but that’s correct I’ll like to access certain information inside the json

Okey so I need to know which agent (forest package) and version you are using please :pray:

Attached the relevant information below, thank you

"liana": "forest-express-sequelize",
"liana_version": "9.3.1",
"stack": {
  "database_type": "postgres",
  "engine": "nodejs",
  "engine_version": "16.16.0",
  "orm_version": "5.15.2"

Okey let me write you a quick script that will ease your work :slight_smile:

// This will help you define your JSON field correctly 
const transformToSchemaType = (object) => {
  if (Array.isArray(object)) {
    return object.map(transformToSchemaType);
  }
  if (typeof object === "object") {
    return {
      fields: Object.keys(object).map((key) => {
        return {
          field: key,
          type: transformToSchemaType(object[key]),
        };
    }),
    };
  }
  return object.name;
};

// Then define your smart field
collection('myCollection', {
  fields: [{
    field: 'myJsonAsRecord',
    // Replace this type with the definition of what's inside your JSON field
    type: transformToSchemaType({
      environmentId: Number,
      enabled: Boolean,
      collections: [
        {
          collectionName: String,
          browseEnabled: Boolean,
          addEnabled: Boolean,
          editEnabled: Boolean,
          deleteEnabled: Boolean,
          exportEnabled: Boolean,
        },
      ],
    }),
    get(myCollectionRecord) {
      return myCollectionRecord.myRealJsonField;
    },
    set(myCollectionRecord, newValue) {
      myCollectionRecord.myRealJsonField = newValue;
    }
  }]
})
1 Like

Hi thank you just tested it this work’s if I see it in the details but once I add the field to a workspace and select a record it doesn’t output any information

Could you send me a video where you show me the configuration of your workspace and then showing when selecting a record that nothing is displayed ? You can send it in private if there is any sensitive data :wink:

It’s certainly a misconfiguration on your agent if you have nothing displayed. Could you share with me the code of your smart field and the name of your json field please :pray: