Code Monkey home page Code Monkey logo

jo's Introduction

jo

jo logo

This is jo, a small utility to create JSON objects

$ jo -p name=jo n=17 parser=false
{
    "name": "jo",
    "n": 17,
    "parser": false
}

or arrays

$ seq 1 10 | jo -a
[1,2,3,4,5,6,7,8,9,10]

It has a manual, and you can read why I wrote jo.

Build from Release tarball

To build from a release you will need a C compiler to install from a source tarball which you download from the Releases page.

tar xvzf jo-1.3.tar.gz
cd jo-1.3
autoreconf -i
./configure
make check
make install

Build from Github

Build Status

To install from the repository, you will need a C compiler as well as a relatively recent version of automake and autoconf.

git clone https://github.com/jpmens/jo.git
cd jo
autoreconf -i
./configure
make check
make install

Install

Homebrew

brew install jo

MacPorts

sudo port install jo

Ubuntu

apt-get install jo

Gentoo

emerge jo

Fedora

dnf install jo

Snap

Thanks to Roger Light, jo is available as a snap package. Use snap install jo from a Linux distro that supports snaps.

Windows

scoop install jo

Windows WSL2

As shown in #175 when using git on Windows WSL2 it should be necessary to disable automatic CRLF conversion in git or the tests will fail:

git config --local core.autocrlf false

AIX

jo builds and passes all tests on AIX 7.1 using the autoconf, automake, gcc, and pkg-config RPMs from IBM's AIX Toolbox for Open Source Software. The xlclang compiler from IBM's xlC/C++ suite for AIX will also build jo.

Others

See also

Credits

  • json.[ch] by 2011 Joseph A. Adams (joeyadams3.14159[at]gmail.com).

jo's People

Contributors

1480c1 avatar arrfab avatar cylon avatar duggan avatar fcambus avatar goostleek avatar gromgit avatar infectormp avatar isotopp avatar itchyny avatar jgarte avatar jo avatar jpmens avatar kcgthb avatar kishorkunal-raj avatar luis02lopez avatar masonm avatar mattn avatar mgamsjager avatar mikemcquaid avatar okapia avatar ralight avatar rikardfalkeborn avatar roguelazer avatar scop avatar stevecheckoway avatar syohex avatar vincentbernat avatar wdscxsj avatar yashi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jo's Issues

How to coerce a number as string?

Got this string which is a version number (say 3.20) value form a variable to jo. But it coerce it to 3.2

How to coerce it to string?

Should jo import a child JSON from a file?

When I want to get a nested JSON, the jo(1) manual suggests to me like this

$ jo obj=$(ls | jo -a)

It means that jo gets keys and values of objects from the argument space.

But that has some problems.

  • It's impossible to generate a JSON the size of which is over than ARG_MAX.
  • jo has to refuse to accept single backslash (single doublequotation neither) without escaping to prevent command injection. So jo can't accept Unicode Escape Sequence strings (e.g. \u1234)

I think file can solve both the problems.

$ ls | jo -a > child.json
$ jo obj:=child.json

(":=" is a sample operator symbol for importing a child JSON from a file)

What do you think?

Cannot create array of large json objects

I was trying to create JSON array of several large JSON objects. I put them in files since they are too large for a command line.
When I tried to use jo like that:
jo -a @file1 @file2
I recognized that files' contents is interpreted as strings, not objects.

I also tried to pass contents of those files as input stream, but there was another problem. Every object must present as a single line in input, but length of input string seems to be limited by BUFSIZ bytes (8192 for me); longer strings are split into several strings that either produce error messages like "missing closing bracket on ..." or are interpreted as strings (not objects).

Escaped double quotes don't work

Value="\"loaderio=${record_value}\"" doesn't work as expected as only works as the unintuitive Value=\"\"loaderio=${record_value}\"\", which can easily break if there are spaces within ${record_value}, I guess. It would break if the variable contains double quotes as well.

Null pointer dereference in member_to_object

Input string foo: can crash the parser with a SIGSEGV. The crash is into member_to_object function.

(gdb) run foo:
Starting program: /dev/shm/jo/jo foo:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000404200 in member_to_object (object=, flags=0, kv=0x7fffffffe87e "foo:") at jo.c:335
335 *q = 0;
(gdb)
(gdb) print /x q
$6 = 0x0

q variable is initialized at jo.c:294 but could be null.

Add openwrt support

Hi,
I was able to compile jo directly on a router (TL-WR1043N) with openwrt/lede 17.01.4 (https://openwrt.org/) installed:

autoreconf -i
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at /usr/bin/automake line 3936.
configure.ac:7: installing 'build-aux/compile'
configure.ac:19: installing 'build-aux/install-sh'
configure.ac:19: installing 'build-aux/missing'
Makefile.am: installing 'build-aux/depcomp'

...

./configure
checking for gcc... gcc
checking whether the C compiler works... yes
...
configure: WARNING: pandoc not found, man pages rebuild will not be possible
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating tests/jo.07.sh
config.status: executing depfiles commands

  Jo.............: version 1.1
  Prefix.........: /usr/local
  C compiler.....: gcc -g -O2
  Pandoc.........: NONE

  Now type 'make [<target>]'
    where the optional <target> is:
      all                - build all binaries
      check              - run the tests
      install            - install everything
- [ ] make

 check
  CC       jo.o
  CC       json.o
  CC       base64.o
  CCLD     jo
make  check-TESTS
make[1]: Entering directory '/root/jo'
make[2]: Entering directory '/root/jo'
FAIL: tests/jo.test 1 -  basic logo
FAIL: tests/jo.test 2 -  basic logo (stdin)
FAIL: tests/jo.test 3 -  basic two values
FAIL: tests/jo.test 4 -  nested with executable
FAIL: tests/jo.test 5 -  nested native
FAIL: tests/jo.test 6 -  strings and numbers; pretty (Vanessa)
PASS: tests/jo.test 7 -  version check
FAIL: tests/jo.test 8 -  data from file: text
FAIL: tests/jo.test 9 -  data from file: base64-encoded
FAIL: tests/jo.test 10 -  array: simple
FAIL: tests/jo.test 11 -  array: true,false,null (native and string)
FAIL: tests/jo.test 12 -  object: geo
FAIL: tests/jo.test 13 -  object: face card jo logo
FAIL: tests/jo.test 14 -  values: with equals signs in them
FAIL: tests/jo.test 15 -  object from file
FAIL: tests/jo.test 16 -  quotes in quotes
FAIL: tests/jo.test 17 -  type coercion
FAIL: tests/jo.test 18 -  nested objects with user-specified delimiter
============================================================================
Testsuite summary for jo 1.1
============================================================================
# TOTAL: 18
# PASS:  1
# SKIP:  0
# XFAIL: 0
# FAIL:  17
# XPASS: 0
# ERROR: 0
============================================================================
See ./test-suite.log
Please report to [email protected]
============================================================================
make[2]: *** [Makefile:735: test-suite.log] Error 1
make[2]: Leaving directory '/root/jo'
make[1]: *** [Makefile:843: check-TESTS] Error 2
make[1]: Leaving directory '/root/jo'
make: *** [Makefile:1042: check-am] Error 2

make install
make[1]: Entering directory '/root/jo'
 build-aux/install-sh -c -d '/usr/local/bin'
/bin/ash: build-aux/install-sh: Permission denied
make[1]: *** [Makefile:548: install-binPROGRAMS] Error 1
make[1]: Leaving directory '/root/jo'
make: *** [Makefile:1055: install-am] Error 2

But I can run the example e.g.:

./jo -p name=jo n=17 parser=false
{
   "name": "jo",
   "n": 17,
   "parser": false
}

Best solution would be to adjust the makefile to support openwrt build system:
https://openwrt.org/docs/guide-developer/helloworld/chapter3

Regards,
Nic

PS: At least jo binary was copied to "/usr/local/bin"

Source package for 1.1 contains 1.0 code

It appears that the "Source code" tarball link on the Github Releases page actually contains the 1.0 code, not 1.1. The "jo-1.1.tar.gz" link contains the proper tarball. The "Source code" zip link is 1.0 as well.

Assertion `utf8_validate(str)' failed

Hello,
I was using American Fuzzy Lop (afl-fuzz) to fuzz input to the jo program on Linux. Is fixing the crashes/aborts from these input files something you're interested in? The input files can be found here: https://github.com/rwhitworth/jo-fuzz.

The files can be executed as ./jo -p < id_filename to cause the issue.

Let me know if I can provide any more information to help narrow down this issue.

Can't nest objects in an array.

Nesting objects in an array doesn't appear to work.

Example...
$ jo -p devices[]="$(jo device=android version=1.2.3)" devices[]="$(jo device=ios version=4.5.6)"

{
  "devices":[]
}

I would have expected the following...

{
  "devices": [
    {
      "device": "android", 
      "version": "1.2.3"
    }, 
    {
      "device": "ios", 
      "version": "4.5.6"
    }
  ]
}

PS: The tool is great BTW... thanks very much for releasing it!!!

How to properly escape spaces in strings in nested `jo` calls?

E.g. this looks proper:

$ jo -p bazz=$(jo foo="bar100")
{
   "bazz": {
      "foo": "bar100"
   }
}

while this is not:

$ jo -p bazz=$(jo foo="bar 100")
Argument `100"}' is neither k=v nor k@v
{
   "bazz": "{\"foo\":\"bar"
}

Is it a bug or am I missing smth. here?

Deeper Nesting Not Working

I'd expect to be able to nest more than one level:

> jo -p this[is][handy]=value
{
   "this": {
      "is": "value"
   }
}
> jo -p this[is[handy]]=value
{
   "this": {
      "is[handy": "value"
   }
}
> jo -p this[][key]=value
{
   "this": [
      "value"
   ]
}

Quoted numbers (read strings) are auto-converted to numbers

This is ok:
=> jo a=1
<= {"a":1}

This is wrong:
=> jo a="1"
<= {"a":1}
=> jo a='1'
<= {"a":1}

This is bad:
=> jo a='1.0'
<= {"a":1}
=> jo a="1.0"
<= {"a":1}

I would expect passing value to json "as it is" if it's quoted, doesn't matter if it is integer or float.

store strings which has spaces in between

i tried assigning variable which has space in between them to json using jo .. Its not accepting.

Lms="build0 build1 build2"
jo LMs=$Lms

Error:
Argument build1' is neither k=v nor k@v Argument build2' is neither k=v nor k@v
{"lms":"build0"}

Latest Release

Hello,

It looks like the latest release tarball does not have a configure script. No big deal to run autoreconf but the install instructions in the README.md don't reflect this.

useage

I didn't know where else to post a question like this, but I'm trying to use jo to convert the output of
lsb_release -a to a json dict.

lsb_release -a outputs lines delimited by a : and whitespace.

Distributor ID:	openSUSE project
Description:	openSUSE Leap 42.3
Release:	42.3
Codename:	n/a

lsb_release -a | jo -p -a 
[
   "LSB Version:\tn/a",
   "Distributor ID:\topenSUSE project",
   "Description:\topenSUSE Leap 42.3",
   "Release:\t42.3",
   "Codename:\tn/a"
]

Alpine package

Hey,

That's a very nice tool I would love to use in mailcow: dockerized for the upcoming watchdog client.

Anybody willing to package this for Alpine?

jo hangs on arrays with failed, unquoted subcommands

If a subcommand fails (e.g. from the s/jo/joe typo below), jo handles it fine in the case of assigning object values (sets to null) but not in some cases with -a, e.g.:

# works fine
$ jo foo=$(joe bar=1)
bash: joe: command not found
{"foo":null}

# quoted, works fine with -a
$ jo -a "$(cat LICENSE2)"
cat: LICENSE2: No such file or directory
[null]

# also works fine with -a
$ jo -a "$(cat2 LICENSE)"
bash: cat2: command not found
[null]

# hangs on unquoted subcommands
$ jo -a $(joe a@t)
bash: joe: command not found

# but doesn't hang on unquoted subcommands with objects
$ jo foo=$(joe a@t)
bash: joe: command not found
{"foo": null}

The difference with and without the -a flag is interesting. But if it's a bash quirk and there's nothing else to do, maybe updating the examples to use quoted subcommands would help?

Empty array?

Is it possible to create an empty array? I have tried:

echo | jo -a which produces [null]

Avoid reading from file if value starts with '@'

Is there any way to avoid the interpretation of the '@' value, which assumes the subsequent string is a file to read from?

I want to construct a json object with @timestamp as the value like this:

{"key": "@timestamp"}

via

jo key="@timestamp"

but I found no way to escape the '@' such that it does not try to read from the timestamp file which does not exist

How to create an array of objects?

I want an output that looks something like this:

`
"targets": [{

    "name" : "somename",
    "path" : "targets/somefile",
    "center" : {
        "x" : 41.821,
        "y" : 12.372,
        "z" : 0.942
    },
    "radius" : 10.0
},
{
    "name" : "somename",
    "path" : "targets/somefile",
    "center" : {
        "x" : 41.821,
        "y" : 12.372,
        "z" : 0.942
    },
    "radius" : 10.0
}],`

Notice that it has an array of objects called "targets". But I can't seem to solve it.

Nesting with .

I was wondering what you think about nesting with . instead of [].

For instance a.b.c = true

would be

{
  a: {
    b: {
      c: true
    }
  }
}

This would also make #27 clearer.

Why three space indentation ?

Looks like jo uses three spaces for indentation.

$ echo -e '{"a":"b"}\n{"c":"d"}' | jo -pa
[
   {
      "a": "b"
   },
   {
      "c": "d"
   }
]

Could this be changed to 2 by default, or perhaps made an option ?

enhancement: `k=@file`

Great project, @jpmens .
An easily dismissable feature idea for you;

As with curl and vault, it could be nice to serialize the contents of a file using the @ prefix.

Example:

$ jo -p authors=@AUTHORS
{
   "authors": "Jan-Piet Mens <[email protected]>"
}

Currently I'm using cat, which is fine, honestly.

$ jo -p authors="$(cat AUTHORS)"

read list from file

is there a way to read variables from file and replace in the elements?

jo -p user=@users
{
"Work": 
[
{
   "user": "user1"
},
{
   "user": "user2"
}
]
}

thanks

Create Object Only aka modular JSON code

I need to be able to generate "sections" of JSON code. Basically, I have several functions that create "peices" of JSON code which in the long run (via heredocs) it builds the entire json file. However, jo seems to generate the entire object, which makes it impossible (unless I'm missing something) to inject the JSON code that is generated into a "section".

Example output:

# count=0;FILESYSTEMS=(); SAVEIFS=$IFS;IFS=$(echo -en "\n\b");for fs in `df -P | awk 'NR!=1'`; do FILESYSTEMS+=("fs$count=${fs}"); (( count++ ));done;jo -p storage="$(jo ${FILESYSTEMS[@]})"
{
   "storage": {
      "fs0": "/dev/mapper/vg_rpidalappnfs-LogVol00                                           10190136      5485908      4179940      57% /",
      "fs1": "tmpfs                                                                           1962684            4      1962680       1% /dev/shm",
      "fs2": "/dev/sda1                                                                        194241       104145        79856      57% /boot",
      "fs3": "/dev/mapper/vg_rpidalappnfs-LogVol02                                          771686280    526993372    205497260      72% /exports",
      "fs4": "dbrisi01nfs.realpage.com:/ifs/rp1/nfs/Backups/Linux/mpsbackup             1399506803008 940223611040 426619512512      69% /backups",
      "fs5": "DBRISI01NFS.realpage.com:/ifs/rp1/nfs/Products/MPS/mps_collection_reports 1399506803200 940223610880 426619512832      69% /serverdata",
      "fs6": "/dev/mapper/vg_dba-lv_dba                                                      20507260        77304     20220284       1% /data/dba"
   }
}

This is great, except for the start and end {} ; what I'd like to be able to do is generate this and pass some sort of argument that says "just generate the json, not the full object" like so:

   "storage": {
      "fs0": "/dev/mapper/vg_rpidalappnfs-LogVol00                                           10190136      5485908      4179940      57% /",
      "fs1": "tmpfs                                                                           1962684            4      1962680       1% /dev/shm",
      "fs2": "/dev/sda1                                                                        194241       104145        79856      57% /boot",
      "fs3": "/dev/mapper/vg_rpidalappnfs-LogVol02                                          771686280    526993372    205497260      72% /exports",
      "fs4": "dbrisi01nfs.realpage.com:/ifs/rp1/nfs/Backups/Linux/mpsbackup             1399506803008 940223611040 426619512512      69% /backups",
      "fs5": "DBRISI01NFS.realpage.com:/ifs/rp1/nfs/Products/MPS/mps_collection_reports 1399506803200 940223610880 426619512832      69% /serverdata",
      "fs6": "/dev/mapper/vg_dba-lv_dba                                                      20507260        77304     20220284       1% /data/dba"
   }

I'm new to JSON so i might be saying some of the wrong terminology, but I think my output shows you what I'm after.

Thanks!

Delimiter is ignored when reading JSON from file

Trying the following test case with jo 1.1 from master branch:
$ jo -p -d . parent.1st_obj.one=1 parent.1st_obj.two=2 parent.2nd_obj:=/tmp/2nd_obj.txt

With the contents of /tmp/2nd_obj.txt being:

{"three":3, "four": 4}

The output returned is:
$ jo -p -d . parent.1st_obj.one=1 parent.1st_obj.two=2 parent.2nd_obj:=/tmp/2nd_obj.txt

{
   "parent": {
      "1st_obj": {
         "one": 1,
         "two": 2
      }
   },
   "parent.2nd_obj": {
      "three": 3,
      "four": 4
   }
}

Though I expected the following:

{
   "parent": {
      "1st_obj": {
         "one": 1,
         "two": 2
      },
      "2nd_obj": {
         "three": 3,
         "four": 4
      } 
   }
}

Is this a bug? Or I'm using it wrong?

can't use Space in value ?

This project is very useful for me. Thanks you guys!
Here is 3 test case, the second one is a bug ? I can use space in string?

jo -p real=$(jo monitor_procs='a')
{
"real": {
"monitor_procs": "a"
}
}
jo -p real=$(jo monitor_procs='a b')
Argument `b"}' is neither k=v nor k@v
{
"real": "{"monitor_procs":"a"
}
jo -p real=$(jo monitor_procs="a,b")
{
"real": {
"monitor_procs": "a,b"
}
}

Embedded arrays, objects

Just playing around, but I'd like some feedback (cc: @itchyny) Is this a good idea?

creates an array: name[]
creates an object: name[member]

jo -p number=17 pass=true geo[lon]=88 geo[cc]=ES point[]=1 point[]=2 geo[lat]=123.45 geo[ok]=false
{
   "number": 17,
   "pass": true,
   "geo": {
      "lon": 88,
      "cc": "ES",
      "lat": 123.45,
      "ok": false
   },
   "point": [
      1,
      2
   ]
}

Support find-like nesting

I think it would be neat to do be able to do nesting with jo without having to use sub-calls to the program. I think that this would be implemented in an intuitive way by copying how find does it.

Take the example from the manual:

jo -p name=JP object=$(jo fruit=Orange hungry@0 point=$(jo x=10 y=20 list=$(jo -a 1 2 3 4 5)) number=17) sunday@0

Could potentially work like this instead with only one call to jo:

jo -p name=JP object= \( fruit=Orange hungry@0 point= \( x=10 y=20 list= \( -a 1 2 3 4 5 \) \) number=17 \) sunday@0

This could potentially allow for more advanced usage of jo using xargs than is currently possible though I acknowledge that it could make syntax a bit harder to parse.

jo hanging on for what ?

When I just typed the command jo without any parameters in my terminal, it just hang on .

Then I tried to input name=jjvein, ok, no stdout, then name, stderror just like 'Argument `name' is neither k=v nor k@v'.

How can i use this way to create my JSON?

woah this is a great app!



                                  .$$$b                     ...                
                                 4$$$$be...                  9$b               
                               zd$$$$$$$$$$$$$e    .z$$$$$$$$$$$               
                            J$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$c             
                      d$- z$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.           
                     $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$L          
                     $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.         
                     $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$b 4       
                     4$$$$$$$$$$P""   '$$F$**$$$$$$$$$$$$$$**$$$$$$$$$L.F      
                     $$$$$$$$$$F .     ^""    ^*$$$$$*     %e$$P*$$$$$$$%      
                    4$$$$$$$$$$$$                *%"              $$$$$        
                    $$$$$$$P           d$$b             d$$c       $$$$        
                    $$$$$$$          .$"  ^                "L    $$$$$F        
                 $.d$$$$$$F .        P                      ^F    "*$$%        
                 *$$$$$$$$$e$       $                        ^c     $$.zF      
                  "$$$$$$$$$$"    ."   4  .                      z 4$$$P       
                    ^$$$$$$"        ^r J  $               z .f   '$$P          
                     *$$$$$       3.z$$$*$L.F          4$$$$$ z   '$"          
                      $$$$$$. 3$.  3$$$$  'P          $$$$F 3$"   $%.          
                       *$$$$$$$$b  $$$     4         .$$$F   'F4$$$e$          
                    .. 4$$$$$$$$P  $""     4         d$$P     F^$$$$F          
                     $$$$$$$$$$"   4.      $         ^.      d" 3$$%           
                     ^"$$$$$ *      $e...z$"          *c    $$   L4F           
                       4P$ $ 4       ""$"F^            "**P"-    $ $           
                       4r4$%.F                    P              $ $           
                        $be$*$e                                .$Ld%           
                         ^    *$.               4$$F          JP**"            
                               .$*$$bec.  ...z$$$$$P$$$bee$$**%                
                              d"                 ""            ^*c             
                             d                                    "c           
                            $                                       "e.        
                           J"            ..       ....   $            "b       
                           $          d$$$$$$$  e$$$$$$b$*$.            *c     
                          4"         d$$$$$$$$$$$$$$$$$$$  "$c           ^$    
                          $      4$% $$$$$$$$$$$$$$$$$$$$    ^"b.          b   
                         JF      $L  $$$$$$$$$$$$$$$$$$$F       ^$e..z      b  
                        4$      J"*k ^$$$$$$$$$$$$$$$$$P           ^P       4  
                       .$      ^P  *b 4$$$$$$$$$$$$$$$F           .P        P  
                      .@       d"   $$$$$$$$$$$$$$$$$$            P        J"  
                     z$"      JF     $$$$$$$$$$$$$$$$$           $        .%   
                    J*       -$       $$$$$$$$$$$$$$$$r         d"       d%    
                   dF       .$         $$$$$$$$$$$$$$$$$c.     J%       d"     
                  $"        $"         $$$$$$$$$$$$$$$$$P*$e$$$%      zP       
                 d"        $          d$$$$$$$$$$$$$$**"   ^$r^r    e"         
                4F       .$          d$$$$$$$$$$$$$$$$r      3r4..$"           
               J$       4$"        .$$$$$$$$$$$$$$$$$$$$      $ $"             
           .$$$$b.     J$         :$$$$$$$$$$$$$$$$$$$$P.de.zd$ $              
      ..eue$$$$$(*   z$"         .$$$$$$$$$$$$$$$$$$$$$$$$$$$C$ $              
   z$P*""""    $$ $d$*           $$$$$$$$$$$$$$$$$$$$$$$$$$$$$"JF              
 d$$  $$*"     $$ $"            :$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"               
 ^$P  ^#*$$- .$"3 $             $$$$$$$$$$$$$$$$$$$$$$$$$$$$$E                 
 $$$$eb zeee$$$$F4F             $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$L  4$.           
 ^ ""#$$""   *$$$"              $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$b           
     *"                         $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$P           
                                $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$            
                           4F  4$$$$$$$$$$$$$$$$$$"4$"""""  $$$$P"             
                           $$$$$$$$$$$$P"*$$$$*"   4"    .. $                  
                           '$$$$$$$$$$F            4$$$e$ 3$P                  
                            3$$$$$$$$"             4$$$$$.d$F                  
                             ^*$$*"*%              J       .                   
                                    b              F       $                   
                                    *.             F      4F                   
                                     $                    J                    
                                      b           4       L                    
                                      4b          $      J-                    
                                       $          %     .F                     
                                      $"         d      $                      
                                     $"         :F      F                      
                                    $          .$      4-                      
                                   d"          d"      3                       
                                  4P          d"       $                       
                                 <$          d"        $                       
                                 d%         J$         $                       
                                 $         4$$        4F                       
                                4F        4" $        4                        
                                $        :#  $        P                        
                                $       4P   *        F                        
                               4F      4F    4r      d                         
                               $      4*      $      $                         
                               P     d"       $     4F                         
                              4"    d%        4     J                          
                              $    J%         4    .F                          
                              $   4%          J    4%                          
                             d"  .$           F    $                           
                            dF   P           d"    F                           
                           J$               $$     F                           
                          dP    J           $$b    L                           
                         4P    ^F           $$$$F  *     Posted by   
                        .$    .$            $$$$$$edF    mchatfield             
                        4$$c.d$"                $$$$$r                         
                        4$$$$$"                  "**$P

Building on SmartOS (and presumably other Solarish) fails

From jo-1.0:

# make
  CC       jo.o
  CC       json.o
json.c:134:18: error: conflicting types for 'uchar_t'
In file included from /usr/include/sys/wait.h:37:0,
                 from /usr/include/stdlib.h:41,
                 from json.c:29:
/usr/include/sys/types.h:100:23: note: previous declaration of 'uchar_t' was here
Makefile:562: recipe for target 'json.o' failed
make: *** [json.o] Error 1

Happy to provide resources for testing / building. (Commenting out json.c:134 "fixes" it, though I imagine that isn't the intention. I don't speak much C, sorry!)

build fail with 0.5 release on CentOS 6

I'm trying to build jo from the 0.5 release tarball on CentOS 6.7, but make check is failing with:

$ make check
  CC       json.o
In file included from json.c:24:
json.h:66: warning: declaration does not declare anything
json.c: In function ‘json_delete’:
json.c:414: error: ‘JsonNode’ has no member named ‘string_’
json.c:420: error: ‘JsonNode’ has no member named ‘children’
json.c: In function ‘json_first_child’:
json.c:482: error: ‘JsonNode’ has no member named ‘children’
json.c: In function ‘json_mkbool’:
json.c:503: error: ‘JsonNode’ has no member named ‘bool_’
json.c: In function ‘mkstring’:
json.c:510: error: ‘JsonNode’ has no member named ‘string_’
json.c: In function ‘json_mknumber’:
json.c:522: error: ‘JsonNode’ has no member named ‘number_’
json.c: In function ‘append_node’:
json.c:539: error: ‘JsonNode’ has no member named ‘children’
json.c:542: error: ‘JsonNode’ has no member named ‘children’
json.c:543: error: ‘JsonNode’ has no member named ‘children’
json.c:545: error: ‘JsonNode’ has no member named ‘children’
json.c:546: error: ‘JsonNode’ has no member named ‘children’
json.c: In function ‘prepend_node’:
json.c:553: error: ‘JsonNode’ has no member named ‘children’
json.c:555: error: ‘JsonNode’ has no member named ‘children’
json.c:556: error: ‘JsonNode’ has no member named ‘children’
json.c:558: error: ‘JsonNode’ has no member named ‘children’
json.c:559: error: ‘JsonNode’ has no member named ‘children’
json.c: In function ‘json_remove_from_parent’:
json.c:609: error: ‘JsonNode’ has no member named ‘children’
json.c:613: error: ‘JsonNode’ has no member named ‘children’
json.c: In function ‘emit_value’:
json.c:982: error: ‘JsonNode’ has no member named ‘bool_’
json.c:985: error: ‘JsonNode’ has no member named ‘string_’
json.c:988: error: ‘JsonNode’ has no member named ‘number_’
json.c: In function ‘emit_value_indented’:
json.c:1009: error: ‘JsonNode’ has no member named ‘bool_’
json.c:1012: error: ‘JsonNode’ has no member named ‘string_’
json.c:1015: error: ‘JsonNode’ has no member named ‘number_’
json.c: In function ‘emit_array_indented’:
json.c:1043: error: ‘JsonNode’ has no member named ‘children’
json.c: In function ‘emit_object_indented’:
json.c:1082: error: ‘JsonNode’ has no member named ‘children’
json.c: In function ‘json_check’:
json.c:1328: error: ‘JsonNode’ has no member named ‘bool_’
json.c:1328: error: ‘JsonNode’ has no member named ‘bool_’
json.c:1331: error: ‘JsonNode’ has no member named ‘string_’
json.c:1333: error: ‘JsonNode’ has no member named ‘string_’
json.c:1336: error: ‘JsonNode’ has no member named ‘children’
json.c:1337: error: ‘JsonNode’ has no member named ‘children’
make: *** [json.o] Error 1

Configure output:

$ ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking stddef.h usability... yes
checking stddef.h presence... yes
checking for stddef.h... yes
checking for stdint.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible realloc... yes
checking for working strtod... yes
checking for strchr... yes
checking for strrchr... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking whether make supports nested variables... yes
checking dependency style of gcc... gcc3
checking whether make supports nested variables... (cached) yes
checking for pandoc... no
configure: WARNING: pandoc not found, man pages rebuild will not be possible
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands

GCC version:

$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)

Can't avoid object nesting

It appears there is no way to embed JSON as a string field within a JSON object. E.g. both jo k1=$(jo k2=v) and jo -- -s k1=$(jo k2=v) generate {"k1":{"k2":"v"}}. I would expect the later to generate {"k1":"{\"k2\":\"v\"}"} via coercion.

Is there a way to generate the later?

Use autoconf to create Makefile

I ported the Makefile by hand to use BSD Makefile syntax so that I could add it to the HardenedBSD ports tree. Ideally, the Makefile shouldn't have to be hand-edited. As much as I dislike autoconf, it might be of use here. In the BSDs (or at least in FreeBSD and HardenedBSD), jo needs to link with the math library (-lm). I'm going to guess you're using a Linux distro that probably doesn't need that. Using autoconf would allow you to detect whether you need to link with any libraries and it would auto-generate the Makefile based on a template (the Makefile.am file). I'd supply a patch with this issue myself, but my time is very limited.

To take a look at what's different between my Makefile and yours, take a look at: master...lattera:master (ignore the obj directory I created)

build failure with 0.4

jo.c: In function 'main':
jo.c:218:2: error: implicit declaration of function 'fileno' [-Werror=implicit-function-declaration]
int ttyin = isatty(fileno(stdin)), ttyout = isatty(fileno(stdout));
^
cc1: all warnings being treated as errors

Makefile CFLAGS

In the Makefile the line CFLAGS=-Wall -Werror replaces the CFLAGS from the environment. This can cause build errors on some systems. Please replace it with CFLAGS+=-Wall -Werror or similar. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.