Frontier Software

Appending

Following from iteration, the next step is to add JSON objects to the version converted to bash.

#!/bin/bash

source /usr/local/lib/json-utils.sh

ExampleGroup 'append new JSON object to an array'

  Example 'add another "workPerformed" object'
    declare -A myarr
    json2array myarr "$(< ../musicevent.json)"
    json1='{
      "@type": "CreativeWork",
      "name": "Sinfonia da Requiem",
      "sameAs": "https://en.wikipedia.org/wiki/Sinfonia_da_Requiem"
    }'
    array_append myarr '"workPerformed"' "$json1"
    When call array2json myarr
    The output should equal '{
  "@context": "https://schema.org",
  "@type": "MusicEvent",
  "location": {
    "@type": "MusicVenue",
    "address": "220 S. Michigan Ave, Chicago, Illinois, USA",
    "name": "Chicago Symphony Center"
  },
  "name": "Shostakovich Leningrad",
  "offers": {
    "@type": "Offer",
    "availability": "https://schema.org/InStock",
    "price": "40",
    "priceCurrency": "USD",
    "url": "/examples/ticket/12341234"
  },
  "performer": [
    {
      "@type": "MusicGroup",
      "name": "Chicago Symphony Orchestra",
      "sameAs": [
        "http://cso.org/",
        "http://en.wikipedia.org/wiki/Chicago_Symphony_Orchestra"
      ]
    },
    {
      "@type": "Person",
      "image": "/examples/jvanzweden_s.jpg",
      "name": "Jaap van Zweden",
      "sameAs": "http://www.jaapvanzweden.com/"
    }
  ],
  "startDate": "2014-05-23T20:00",
  "workPerformed": [
    {
      "@type": "CreativeWork",
      "name": "Britten Four Sea Interludes and Passacaglia from Peter Grimes",
      "sameAs": "http://en.wikipedia.org/wiki/Peter_Grimes"
    },
    {
      "@type": "CreativeWork",
      "name": "Shostakovich Symphony No. 7 (Leningrad)",
      "sameAs": "http://en.wikipedia.org/wiki/Symphony_No._7_(Shostakovich)"
    },
    {
      "@type": "CreativeWork",
      "name": "Sinfonia da Requiem",
      "sameAs": "https://en.wikipedia.org/wiki/Sinfonia_da_Requiem"
    }
  ]
}'
    The status should be success
    The error should be blank
  End


End