Jump to content
Flirc Forums

How I created my brand JSON file


Recommended Posts

A forum member asked how I converted a CSV file I had created originally into a JSON file and I figured I would share with everyone.

I pulled my codes from here https://www.remotecentral.com/cgi-bin/codes/yamaha/rx-v1000/

Here is how I got my json file.  I am familiar with the Linux command line so I performed the following steps.

Before I show these let me say that an easier way could be to open a spreadsheet program and copy the button name into one column and the code for the button into another column. The second column needs to have the spaces between the numeric codes replaced with commas. You should then be able to save to the CSV file. It is possible you spreadsheet program may be able to save the file to JSON. If not, you may be able to use an online tool to do that basic work.

I followed the following steps to dump the html page into a bit more of a manageable file. The steps below have been modified from the blog post.


lynx -dump 'https://www.remotecentral.com/cgi-bin/codes/yamaha/rx-v1000/' | sed -e 's/^ *//' | tr -s ' ' ',' | sed 's/$/,/' > dumped_page.txt

I then ran the following commands to strip out more of what I did not need.

sed -i '/\[filler\.gif\]/d' dumped_page.txt
sed -i '/\(Copy,to,Clipboard\)/d' dumped_page.txt
sed -i '/\[filler\.gif\]/d' dumped_page.txt

 

I then opened the dumped_page.txt file into a text editor and removed all the text I did not need. How I found that was by looking for these couple of lines of text

  Remote Model: RAV222
  [filler.gif]
  Power
  ([23]Copy to Clipboard)


Power is where my first button started so I removed every line above Power in the file.

I then looked for the equivalent of the bottom the button codes.

 [filler.gif]
  [ < Back | Page: 1 [43]2 | [44]Next > ]
  [filler.gif]


I removed everything starting from the first filler.gif line to the bottom of the file.

I then combined all the codes for each button onto one line.

BEFORE

Stadium,
0000,006b,0022,0002,0156,00ad,0015,0015,0015,0041,0015,0015,0015,0041,
0015,0041,0015,0041,0015,0041,0015,0015,0015,0041,0015,0015,0015,0041,
0015,0015,0015,0015,0015,0015,0015,0015,0015,0041,0015,0041,0015,0015,
0015,0041,0015,0041,0015,0015,0015,0015,0015,0015,0015,0041,0015,0015,
0015,0041,0015,0015,0015,0015,0015,0041,0015,0041,0015,0041,0015,0015,
0015,05f8,0156,0057,0015,0e57,

AFTER

Stadium,0000,006b,0022,0002,0156,00ad,0015,0015,0015,0041,0015,0015,0015,0041,0015,0041,0015,0041,0015,0041,0015,0015,0015,0041,0015,0015,0015,0041,0015,0015,0015,0015,0015,0015,0015,0015,0015,0041,0015,0041,0015,0015,0015,0041,0015,0041,0015,0015,0015,0015,0015,0015,0015,0041,0015,0015,0015,0041,0015,0015,0015,0015,0015,0041,0015,0041,0015,0041,0015,0015,0015,05f8,0156,0057,0015,0e57

Since I know I am working with a CSV file I removed the last comma from each line since I do not need it and it could cause problems when creating the JSON file

I saved that file which now gives me 20 lines for my remote and then i ran another script to convert the CSV into a JSON file. Notice that I filled in the "types", "brand", and "model" with what was relevant to me. I redirected the output of the script to a file.

#!/usr/bin/env bash

cat << EOF
{
  "header": {
    "version": "2.0"
  },
  "types": [
    "devices.audio"
  ],
  "brand": "Yamaha",
  "model": "RX V-1000",
  "signals": [
EOF

while read -r line; do
    _label=$(echo "${line}" | cut -d ',' -f 1)
    _code=$(echo "${line}" | cut -d ',' -f 2- | tr '[:lower:]' '[:upper:]')
    cat << EOF
    {
        "label": "${_label}",
        "code": "${_code}",
        "protocol": "PRONTO"
    },
EOF

done < dumped_page.txt

cat << EOF
  ]
}
EOF

 

One thing to keep on mind is that JSON is picky about commas and where then end up and the end of blocks. I will show what I mean with the last two entries of my JSON file.

   {
       "label": "RO Concert",
       "code": "0000,006B,0022,0002,0156,00AD,0015,0015,0015,0041,0015,0015,0015,0041,0015,0041,0015,0041,0015,0041,0015,0015,0015,0041,0015,0015,0015,0041,0015,0015,0015,0015,0015,0015,0015,0015,001
5,0041,0015,0015,0015,0015,0015,0041,0015,0041,0015,0015,0015,0015,0015,0015,0015,0041,0015,0041,0015,0041,0015,0015,0015,0015,0015,0041,0015,0041,0015,0041,0015,0015,0015,05F8,0156,0057,0015,0E57",
       "protocol": "PRONTO"
   },   <----- NOTICE THIS COMMA
   {
       "label": "Stadium",
       "code": "0000,006B,0022,0002,0156,00AD,0015,0015,0015,0041,0015,0015,0015,0041,0015,0041,0015,0041,0015,0041,0015,0015,0015,0041,0015,0015,0015,0041,0015,0015,0015,0015,0015,0015,0015,0015,001
5,0041,0015,0041,0015,0015,0015,0041,0015,0041,0015,0015,0015,0015,0015,0015,0015,0041,0015,0015,0015,0041,0015,0015,0015,0015,0015,0041,0015,0041,0015,0041,0015,0015,0015,05F8,0156,0057,0015,0E57",
       "protocol": "PRONTO"
   }   <----- IT CANNOT EXIST AT THE END
 ]
}

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...