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

New field type: JSON #190

Closed
JedWatson opened this issue Feb 24, 2014 · 12 comments · May be fixed by #2136
Closed

New field type: JSON #190

JedWatson opened this issue Feb 24, 2014 · 12 comments · May be fixed by #2136

Comments

@JedWatson
Copy link
Member

Would store a JSON string in the database, and have a nice renderer / editor in the Admin UI.

Could use pretty-stringify for formatting the JSON, and Code Mirror for editing.

Would validate JSON on save.

@jdarling
Copy link
Contributor

Would be nice if it would take dirty JSON and clean it up:

input

{
  myKey: "My Value",
  "anotherKey": 'another value'
}

output

{"myKey": "My Value", "anotherKey": "Another Value"}

Personally I get so tired of having to drop to the console or node.js paste in perfectly valid code and then use JSON.stringify(obj) to get out "Valid" JSON.

JedWatson added a commit that referenced this issue Mar 7, 2014
Create new field type "code" #190 using code mirror.
@jorgecid
Copy link

@jbalde
Copy link
Contributor

jbalde commented Jun 13, 2014

You can use "code" field.

Sample:

User.add({
    name: { type: Types.Name, required: true, index: true },
    email: { type: Types.Email, initial: true, required: true, index: true },
    password: { type: Types.Password, initial: true, required: false },
.....
    configuration: { type: Types.Code, lang: 'json' }
);

If language is json or javascript, show lint validator.

Supported languages:

  • c
  • c++
  • objetivec
  • css
  • asp
  • c#
  • vb
  • xml
  • php
  • html
  • ini
  • js
  • java
  • coffee
  • lisp
  • perl
  • python
  • sql
  • json
  • less
  • sass
  • sh
  • ruby
  • jsp
  • tpl
  • jade

@uptownhr
Copy link

problem with using "Types.Code" is that it will store the JSON as text. Meaning you will not be able to run queries against it. I really wish you can throw in raw objects. This is supported by mongodb, mongoose by default, why is this option not available?

@morenoh149
Copy link
Contributor

@uptownhr someone has to code it. There's probably no technical reason blocking this.

jbalde pushed a commit to jbalde/keystone that referenced this issue Jan 22, 2016
jbalde pushed a commit to jbalde/keystone that referenced this issue Jan 22, 2016
@jbalde
Copy link
Contributor

jbalde commented Jan 22, 2016

I created a field type Types.Json that store in mongo a JSON in raw format. I commit two pull requests to branch 0.3.x and master.

@kadosh1000
Copy link

Hi I have published my npm package:
https://github.com/kadosh1000/keystone-custom-fieldtypes

It allows you to create custom field types, and copy your custom fieldTypes from a selected dir into the keystone's fields dir and registers it.

@mxstbr
Copy link
Collaborator

mxstbr commented Apr 29, 2016

We're closing all feature requests to keep the issue tracker unpolluted. From now on submit feature requests on productpains.com!

@mxstbr mxstbr closed this as completed Apr 29, 2016
@ChristianRich
Copy link

This worked for me and allowed my to save an arbitrary object, only it's not visible in the Admin UI because it is unsupported. But you can query the fields just fine.

list.schema.add({
    model: mongoose.Schema.Types.Mixed
});

thesverre pushed a commit to CappelenDamm/keystone that referenced this issue Apr 4, 2017
sheldon-sminq added a commit to getmarkk/keystone that referenced this issue Jan 2, 2018
sheldon-sminq added a commit to getmarkk/keystone that referenced this issue Jan 2, 2018
@gemscng
Copy link
Contributor

gemscng commented Nov 20, 2018

@mxstbr @JedWatson i have make a pull request on latest version base on . @jbalde
code. keystonejs/keystone#4855

@victusfate
Copy link

victusfate commented Oct 3, 2019

since this has been around for 3 years, is there a suggested work around for existing data schema with Mixed types (responses from third parties etc)

trying out keystone v5 and was hoping to hit the ground running with a light cms around my data

    transcription_job: { type: JSON, schemaDoc: 'response of transcription job' }

going with Text for now and hoping it renders ok in gets

@internetErik
Copy link

@victusfate
Not a great solution, but you could just save JSON as plain test - perhaps in a Textarea type - and after reading it in from mongo in your controller run JSON.parse on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.