How to format notification service data?

I’d like to do some tests of notification with graphic attachments.
I’ve read this page: https://companion.home-assistant.io/en/notifications/attachments

I’m testing with the /developer-tools/service at present and can send a simple message which works just fine:

{"message":"hello"}

Being a newcomer to JSON/YAML … how do I convert the below into that “single line” command so that I can test?

- alias: Notify Mobile app
    trigger:
      ...
    action:
      service: notify.mobile_app_<your_device_id_here>
      data:
        message: "Something happened at home!"
        data:
          attachment:
            url: "https://github.com/home-assistant/home-assistant-assets/blob/dfd755bd8fb86dc2fdde1c70a8fc2fbcbec8a6da/logo-round-192x192.png?raw=true"
            content-type: png
            hide-thumbnail: false

I you’re lazy you can alway try to copy and paste into an online converter like this one:

https://www.json2yaml.com/convert-yaml-to-json

Copying and pasting this:

data:
  message: "Something happened at home!"
  data:
    attachment:
      url: "https://github.com/home-assistant/home-assistant-assets/blob/dfd755bd8fb86dc2fdde1c70a8fc2fbcbec8a6da/logo-round-192x192.png?raw=true"
      content-type: png
      hide-thumbnail: false

will give you this:

{
  "data": {
    "message": "Something happened at home!",
    "data": {
      "attachment": {
        "url": "https://github.com/home-assistant/home-assistant-assets/blob/dfd755bd8fb86dc2fdde1c70a8fc2fbcbec8a6da/logo-round-192x192.png?raw=true",
        "content-type": "png",
        "hide-thumbnail": false
      }
    }
  }
}

When you run this to a JSON formatter like

You will get this:

{"data":{"message":"Something happened at home!","data":{"attachment":{"url":"https://github.com/home-assistant/home-assistant-assets/blob/dfd755bd8fb86dc2fdde1c70a8fc2fbcbec8a6da/logo-round-192x192.png?raw=true","content-type":"png","hide-thumbnail":false}}}}
4 Likes

Thanks very much!

Thank you Metbril for finding this nice tool, I also found another JSON tool on the same site which helps to view json in tree view. JSON Parser

You can also share your love by clicking the heart button below the post. :wink:

1 Like