Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Parse property from json file Post 303042445 by Neo on Wednesday 25th of December 2019 03:20:07 AM
Old 12-25-2019
FYI, many of us "everyday JSON slingers" here do not process JSON files and JSON API output with grep, awk and sed, etc.

We process JSON with JSON processing tools.

Some use Javascript, PHP and Python (like me) and the built-in JSON processing or libs available, others here use "sed-like" jq.

Code:
https://stedolan.github.io/jq/

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

source a property file in script give error

I have sourced a property file in my script like this to load some variables in the script Then i am able to echo all the property file values inside script but the script is not able to recognize other unix commands #!/bin/bash . build.properties mkdir build i am getting error ... (3 Replies)
Discussion started by: codeman007
3 Replies

2. Shell Programming and Scripting

perl use property file for variables

if I have a file that contains variables. How do I assign them in a script. file p=c e=g Thanks (3 Replies)
Discussion started by: 3junior
3 Replies

3. Shell Programming and Scripting

change word in a property file

Hi, I have a property file called "inspector.properties". In this property file stands the following: inspect=ON Now I want to have a shell script that when you run it, changes the ON in OFF in this property file. Is this possible with sed? Can anybody help me with this? Tnx very much. (5 Replies)
Discussion started by: thebladerunner
5 Replies

4. Shell Programming and Scripting

Report a missing property and property value mis match script.

Hi All, I have 2 properties files - one is a master templete and other one is a node specific properties file, I need to comapre these 2 properties files and make sure the node Specific properties file contains all the properties in the master temple properties file else report the missing... (5 Replies)
Discussion started by: jayka
5 Replies

5. Shell Programming and Scripting

Reading a property file through shell script???

Hi! i need a script that can read a property file. i.e., A script to read a "property" from property file. Read the property value and based on value of property, decide whether to start the some dataload activity or not. Its urngent. Can anyone help me out???:( (7 Replies)
Discussion started by: sukhdip
7 Replies

6. Shell Programming and Scripting

reading and updating property file

I have to do a read operation for a field in property file, which looks like follows: 123|xyz|datetime|count '|' is delimiter. Finally I managed to read the contents of property file using statement like cut -d"|" -f1 $PROPERTIES_FILE | tr '\n' ' ' <-- Reading first column But now I... (2 Replies)
Discussion started by: rakeshranjanscs
2 Replies

7. Shell Programming and Scripting

Property file processing in unix

Hi genius, Following is the problem. We have one templete file(input file) where some variables will be used Example: word1 word2 &{word3} word4 ${word5} word6 And also we have one property file where we define these variables Example: word3= something Word5= something Need to read... (5 Replies)
Discussion started by: gjarms
5 Replies

8. Shell Programming and Scripting

URL extraction from JSON file

I'm trying to export URLs from within a JSON file which in turn resulted from export of Mozilla-Firefox bookmarks. Its single line file with below given values from awk $ awk 'END { print NR }' bookmarks.json 1 $ awk 'END { print NF }' bookmarks.json 2706 $ awk -F, 'END { print NF }'... (6 Replies)
Discussion started by: busyboy
6 Replies

9. Shell Programming and Scripting

Bash script - cygwin (powershell?) pull from GitHub API Parse JSON

All, Have a weird issue where i need to generate a report from GitHub monthly detailing user accounts and the last time they logged in. I'm using a windows box to do this (work issued) and would like to know if anyone has any experience scripting for GitAPI using windows / cygwin / powershell?... (9 Replies)
Discussion started by: ChocoTaco
9 Replies
CGI::Application::Plugin::JSON(3pm)			User Contributed Perl Documentation		       CGI::Application::Plugin::JSON(3pm)

NAME
CGI::Application::Plugin::JSON - easy manipulation of JSON headers SYNOPSIS
use CGI::Application::Plugin::JSON ':all'; # add_json_header() is cumulative $self->add_json_header( foo => 'Lorem ipsum...'); $self->add_json_header( bar => [ 0, 2, 3, 4 ] ); $self->add_json_header( baz => { stuff => 1, more_stuff => 2 } ); # json_header() is not cumulative $self->json_header( foo => 'Lorem ipsum...'); # in case we're printing our own headers print "X-JSON: " . $self->json_header_string(); # clear out everything in the outgoing JSON headers $self->clear_json_header(); # or send the JSON in the document body $self->json_body( { foo => 'Lorem ipsum', bar => [ 0, 2, 3 ] } ); # send the JSON back in the document body, but execute it using a Javascript callback $self->json_callback('alert', { foo => 'Lorem ipsum', bar => [ 0, 2, 3 ] } ); DESCRIPTION
When communicating with client-side JavaScript, it is common to send data in "X-JSON" HTTP headers or through the document body as content- type "application/json". This plugin adds a couple of convenience methods to make that just a little bit easier. HEADER METHODS
json_header This method takes name-value pairs and sets them to be used in the outgoing JSON. It is not cummulative and works similarly to "header_props". Use it only if you have all of the values up front. In most cases add_json_header is probably what you want. # only the 2nd call will actually set data that will be sent $self->json_header( foo => 'Lorem ipsum...'); $self->json_header( bar => [ 0, 2, 3, 4 ] ); add_json_header This method takes name-value pairs and sets them to be used in the outgoing JSON. It is cummulative and works similarly to "header_add"; meaning multiple calls will add to the hash of outgoing values. # both 'foo' and 'bar' will exist in the hash sent out $self->json_header( foo => 'Lorem ipsum...'); $self->json_header( bar => [ 0, 2, 3, 4 ] ); clear_json_header This method will remove anything that was previously set by both json_header and add_json_header. This means that no "X-JSON" header will be sent. json_header_string This method will create the actual HTTP header string that will be sent to the browser. This plugin uses it internally to send the header, but it might be useful to use directly if you are printing your own HTTP headers (using a "header_type" of "none"). $self->header_type('none'); print $self->json_header_string(); json_header_value This method will return the values being sent in the JSON header. If you pass in the key of the value you want, you will get just that value. Else all name-value pairs will be returned. my $value = $self->json_header_value('foo'); my %values = $self->json_header_value(); BODY METHODS
json_body This method will take the given Perl structure, turn it into JSON, set the appropriate content-type, and then return the JSON. return $self->json_body({ foo => 'stuff', bar => [0,1,2,3]} ); json_callback This method will take the given Perl structure, turn it into JSON, set the appropriate content-type, and then return a Javascript snippet where the given callback is called with the resulting JSON. return $self->json_callback('alert', { foo => 'stuff', bar => [0,1,2,3]} ); # would result in something like the following being sent to the client alert({ foo => 'stuff', bar => [0,1,2,3]}); MISC METHODS
to_json This method is just a convenient wrapper around JSON::Any's "encode". from_json This method is just a convenient wrapper around JSON::Any's "decode". AUTHOR
Michael Peters, "<mpeters@plusthree.com>" BUGS
Please report any bugs or feature requests to "bug-cgi-application-plugin-viewsource@rt.cpan.org", or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-JSON <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application- Plugin-JSON>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. COPYRIGHT &; LICENSE Copyright 2006 Michael Peters, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.4 2011-11-11 CGI::Application::Plugin::JSON(3pm)
All times are GMT -4. The time now is 04:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy