Json field

From EPrints Documentation
Revision as of 18:36, 14 June 2022 by Drn@ecs.soton.ac.uk (talk | contribs) (Compatible Field Types =)
Jump to: navigation, search

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects

Metadata Fields: Arclanguage - Base64 - Bigint - Boolean - Compound - Counter - Dataobjref - Date - Decimal - Email - Fields - Float - Id - Idci - Image - Int - Itemref - Keywords - Langid - Longtext - Longtext_counter - Multilang - Multipart - Name - Namedset - Pagerange - Recaptcha - Relation - Search - Secret - Set - Storable - Subject - Subobject - Text - Time - Timestamp - Url - Uuid



Like a Compound field, this field is designed to have a number of subfields which are all stored and displayed under the same parent field. However, unlike the Compound field, instead of storing each one in its own field or table, we store all the subfields in a single database field as a JSON string.


This module requires the HTML::Entities and JSON::Parse Perl libraries installed.


The field works by providing a json_config. parameter, for example:

    name => "fieldname", 
    type => "json", 
    json_config => [
            name => "subfield1",
            type => "text"
            name => "subfield2",
            type => "number"
            name => "subfield3",
            type => "richtext"
            name => "subfield4",
            type => "namedset"
            set_name => "example_set"

Compatible Field Types

For the sub-fields the following field types are currently compatible:

Other field types are likley to be compatible as long as there values can be embedded within JSON syntax.

These all render as their standard EPrints counterparts would, however are rendered by JavaScript instead of the standard EPrints form renderer.

The corresponding phrases for each subfield are in the format:

  • eprint_fieldname_${fieldname}_${subfieldname}
  • eprint_fieldhelp_${fieldname}_${subfieldname}

Table View

The JSON field can also be used to render a table, with a fixed number of rows. In this scenario, the JSON string stored is a JSON array.

Use render_table to turn on the table mode, and table_row_count to specify the number of rows.

In some tables, you may want to skip certain subfields - e.g. the third row doesn't have subfield 3. If the value of the subfield is __json_field_control__skip, the subfield will not render.

If using resizeable richtext in your tables, you can use the reset button to put the fields/table columns back to their default size.

If you set table_allow_hide_rows to be true, you get a select to select which rows you want to appear and which not. `table_show_hide_rows` default is true. This will show the selector. Allows you to hide on some views, e.g. allowing certain workflows to determine rows shown, and certain to edit values

If you set table_hide_table</ttt> to be true, the table is hidden, e.g. allowing certain workflows to determine rows shown, and certain to edit values

If you set `table_hide_rows_render_js`, you can provide custom JS to render the hide rows selector and how the json is updated.

List View

The JSON field can also be used to display the fields in multiple columns, instead of the standard one-after-the-other. This is helpful in scenarios where you have lots of small fields, e.g. a series of boolean checkboxes.

Use display_as_list to turn on the list mode, and `display_as_list_cols` to specify the number of columns you want.


You can provide an input_lookup_url as per standard [[Category::MetaField|MetaFields]].

When added, each subfield will have lookup capabilities. It will send the following as parameters to the input_lookup_url

  • q - the query
  • field - the json field name
  • json_field - the subfield name, per the json_config

A basic CGI script that accepts these parameters and uses them to lookup on a particular subfield is provided.


name default description
display_as_list undefined
display_as_list_cols undefined
json_config undefined
hidden_fields undefined
readonly_fields undefined
render_table undefined
readonly_fields undefined
table_allow_hide_rows undefined
table_hide_rows_render_js undefined
table_dynamic_row_count undefined
table_hide_table undefined
table_row_count undefined
table_show_hide_rows undefined

Required Phrases



Json fields are stored in the database as

fieldname LONGTEXT