Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having trouble creating simple json #37

Open
hacktek opened this issue Dec 14, 2014 · 2 comments
Open

Having trouble creating simple json #37

hacktek opened this issue Dec 14, 2014 · 2 comments

Comments

@hacktek
Copy link

hacktek commented Dec 14, 2014

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!

@hacktek
Copy link
Author

hacktek commented Dec 14, 2014

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.

@zot
Copy link

zot commented Dec 15, 2014

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
#37 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants