9.4.8 adshparsejson command (analyzes JSON data)
Syntax
adshparsejson name
Description
This command is a command that is used with script development parts. We recommend using parts for making JSON operation of script development parts when analyzing JSON data.
This command searches for a name from JSON data that is read from the standard input, and then outputs the value that supports the fully matched name, using line breaks as delimiters.
- [Only for UNIX]
-
When inputting JSON data for encoding having a different value from the environment variable LANG of an environment where JP1/Advanced Shell will operate, unified encoding can be operated while the adshparsejson command is executed by setting a value for the shell variable ADSH_PARSER_LANG. Set a value that can be specified for the environment variable LANG for the shell variable ADSH_PARSER_LANG. For example, if the following condition is applied, execute the adshparsejson command after setting JA_JP.UTF-8 for the shell variable ADSH_PARSER_LANG to unify and operate encoding.
-
The value (Ja_JP) indicating SJIS is set for the environment variable LANG in AIX.
-
Encoding inputs JSON data of UTF-8.
-
Arguments
- name
-
This command specifies the name to be searched.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 |
Termination with an error |
Notes
-
If matching item is not found, the command terminates with an error.
-
If the data having the same name is nested, output the value corresponding to the outermost name of data.
Examples: (test.json) : {"num":{"id":"0001","num":200}}
If the aforementioned data is searched by using num, {"id":"0001","num":200} is output. In this case, the value (200) corresponding to the inner name of the data can be output by specifying the following:
adshparsejson num < test.json | adshparsejson num
Examples
JSON data (data.json) { "city": [ { "name":"Yokohama", "id":"0001", "value":{ "A":200, "B":100 } }, { "name":"Kawasaki", "id":"0002", "value":{ "A":100, "B":300 } } ] } adshparsejson name < data.json # The following message is output: "Yokohama" "Kawasaki" adshparsejson value < data.json # The following message is output: (Output the nested data as it is) { "A":200, "B":100 } { "A":100, "B":300 } adshparsejson B < data.json # The following message is output: 100 300