jshon
                                
                                 jshon copied to clipboard
                                
                                    jshon copied to clipboard
                            
                            
                            
                        Having trouble creating simple json
Hey, great job on this.
I'm trying to create what I believe would be a pretty simple json with nested objects very similar to Youtube's "add to playlist":
{ 'snippet': { 'playlistId': '{PLAYLIST_ID}', 'resourceId': { 'kind': 'youtube#video', 'videoId': '{VIDEO_ID}' } 'position': 0 } }
However, I for the life of me can't get "playlistId" to be inside of "snippet". Is this possible with jshon? What am I missing?
Thanks!
Answering my own question here, seems I was able to do it like this:
$ jshon -n {} -i snippet -a -n {} -p -s 12345 -i playlistId -p -a -n {} -i resourceId -e resourceId -s youtube -i kind -s 67890 -i videoId -p -s 0 -i position -p <<< "{}" { "snippet": { "playlistId": "12345", "resourceId": { "kind": "youtube", "videoId": "67890" }, "position": "0" } }
Not sure if it's efficiend but it's working.
Instead of building up the entire JSON object by hand, you may want to use jshon to edit a template structure. This should simplify your code. Here's an example. This takes this structure as input:
{ "snippet": { "position": 0, "playlistId": 33, "resourceId": { "kind": "youtube", "videoId": 67890 } } }
edits it like this:
jshon <<< '{"snippet":{"playlistId":33,"resourceId":{"kind":"youtube","videoId":67890},"position":0}}' -e snippet -s 34 -i playlistId -e resourceId -s 67891 -i videoId -p -p
and returns this structure:
{ "snippet": { "position": 0, "playlistId": "34", "resourceId": { "kind": "youtube", "videoId": "67891" } } }
-- Bill
On Sun, Dec 14, 2014 at 8:53 PM, hacktek [email protected] wrote:
Answering my own question here, seems I was able to do it like this:
$ jshon -n {} -i snippet -a -n {} -p -s 12345 -i playlistId -p -a -n {} -i resourceId -e resourceId -s youtube -i kind -s 67890 -i videoId -p -s 0 -i position -p <<< "{}" { "snippet": { "playlistId": "12345", "resourceId": { "kind": "youtube", "videoId": "67890" }, "position": "0" } }
Not sure if it's efficiend but it's working.
— Reply to this email directly or view it on GitHub https://github.com/keenerd/jshon/issues/37#issuecomment-66924496.