# Build array of strings and wrap them in quotations marks

**URL:** <https://talk.jekyllrb.com/t/build-array-of-strings-and-wrap-them-in-quotations-marks/3577>\
**Category:** Help\
**Created:** [November 11, 2019, 3:20pm UTC](https://talk.jekyllrb.com/t/build-array-of-strings-and-wrap-them-in-quotations-marks/3577 "2019-11-11T15:20:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pke](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/pke/32/2009_2.png) [@pke](https://talk.jekyllrb.com/u/pke)\
**Post date:** [November 11, 2019, 3:20pm UTC](https://talk.jekyllrb.com/t/build-array-of-strings-and-wrap-them-in-quotations-marks/3577/1 "2019-11-11T15:20:26Z")

</div>

I am trying to generate this output:

```auto
["index", "last", "first"]

```

from an inital (potentially empty) string:  
`{%- assign rels = link.rel -%}`

and conditional additions to that string:  
`{%- if first -%}{%- assign rels = rels | append: ",first" -%}{%- endif -%}`  
`{%- if last -%}{%- assign rels = rels | append: ",last" -%}{%- endif -%}`

I am then splitting the `rels` and try to remove empty items (not working)  
`{%- assign rels = rels | split: “,” | compact -%}

And then I render it:

```auto
[
    {% for rel in rels %}
      "{{rel}}"
      {% unless forloop.last %},{% endunless %}
    {% endfor %}
  ]

```

I hope there is an easier, more compact way to do that?

Something like this would be nice:

`[{{ rels | split: "," | prepend: '"' | append: '"' }}]`

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [November 11, 2019, 4:10pm UTC](https://talk.jekyllrb.com/t/build-array-of-strings-and-wrap-them-in-quotations-marks/3577/2 "2019-11-11T16:10:30Z")

</div>

Can be easily achieved by using the `inspect` filter if you have control over the input string.  
For example, test with the following sample page content:

```auto
---
rels: index,last,first
---

{{ page.rels | split: "," | inspect }}

```

---

<div class="post-metadata">

**Author:** ![pke](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/pke/32/2009_2.png) [@pke](https://talk.jekyllrb.com/u/pke)\
**Post date:** [November 11, 2019, 9:10pm UTC](https://talk.jekyllrb.com/t/build-array-of-strings-and-wrap-them-in-quotations-marks/3577/3 "2019-11-11T21:10:00Z")

</div>

Thanks! Sounded nice, but `inspect` outputs quoted entities. But I need to use it in json, so I need the real quotation marks and not `&quot;`

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [November 12, 2019, 3:40am UTC](https://talk.jekyllrb.com/t/build-array-of-strings-and-wrap-them-in-quotations-marks/3577/4 "2019-11-12T03:40:48Z")

</div>

You can also try using the `jsonify` filter.  
That said, I get **`<p>["index", "last", "first"]</p>`** when testing with either Jekyll 3.8.6 or Jekyll 4.0.0.

Jekyll’s Markdown converter generates output meant for HTML pages. It doesn’t know how to generate JSON.

Your use case is not exactly clear now.
