# Best way to store key-value pairs in plugin settings?

**URL:** <https://meta.discourse.org/t/best-way-to-store-key-value-pairs-in-plugin-settings/68059>\
**Category:** Development\
**Created:** [15 أغسطس 2017، 6:47ص UTC](https://meta.discourse.org/t/best-way-to-store-key-value-pairs-in-plugin-settings/68059 "2017-08-15T06:47:58Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![john-lynch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/john-lynch/32/81514_2.png) [@john-lynch](https://meta.discourse.org/u/john-lynch)\
**Post date:** [15 أغسطس 2017، 6:47ص UTC](https://meta.discourse.org/t/best-way-to-store-key-value-pairs-in-plugin-settings/68059/1 "2017-08-15T06:47:58Z")

</div>

I’m working on a very simple plugin to perform simple textual replacements in a Discourse post. Specifically, when a user types `/keyword` in a post, I want to replace that sequence with an arbitrary string (in this case, a kaomoji, so that I can map `/shrug` to `¯\_(ツ)_/¯`). Yes, it’s very silly.

In any case, the plugin is mostly complete: I can detect the pattern and perform the replacement in my dev environment. However, the mapping from keyword to kaomoji is currently specified as a Javascript literal in the plugin’s discourse-markdown Javascript file. That’s not great.

I’d like to be able to define the mapping of keywords to kaomoji (or whatever) in the plugin’s settings so that I don’t have to modify a server-side Javascript file every time I want to change what mappings are allowed. I cannot find a good way to do this. The closest I’ve come is using a “list” setting (with values like `shrug:¯\_(ツ)_/¯`, but that gives me back a string of `|` seperated strings, which is problematic when working with values like kaomoji that are highly likely to contain `|` in them.

I could hack around this by disallowing `|` in the mapping and splitting the list myself, but before I do, I thought I’d ask if there were a better way than “list” to do what I’m talking about. Is there any reasonable way to create and edit set of key-value pairs through a plugin’s settings? What’s the best way to approach this for both ease of editing and maximum permissiveness in the allowed characters?

---

_[View the full topic](https://meta.discourse.org/t/best-way-to-store-key-value-pairs-in-plugin-settings/68059)._
