This is jo, a small utility to create JSON objects

Related tags

JSON jo
Overview

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 git://github.com/jpmens/jo.git
cd jo
autoreconf -i
./configure
make check
make install

Homebrew

brew install jo

Ubuntu

apt-get install jo

Gentoo

emerge jo

Snap

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

Others

See also

Credits

Comments
  • Ignore keys with empty, null, [] or {} values when -n is specified

    Ignore keys with empty, null, [] or {} values when -n is specified

    Suppose you are processing a directory recursively, then the following command will omit the "subdir" field altogether and returns "{}" if the sub directory is empty:

    jo -n subdir=$(cd subdir && ls | jo -n -a)

    opened by patrick-yingxi-pan 20
  • read list from file

    read list from file

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

    jo -p [email protected]
    {
    "Work": 
    [
    {
       "user": "user1"
    },
    {
       "user": "user2"
    }
    ]
    }
    

    thanks

    question 
    opened by FernandoMiguel 11
  • Assertion `utf8_validate(str)' failed

    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.

    bug help wanted 
    opened by rwhitworth 11
  • Assertion `utf8_validate(str)' failed - again?

    Assertion `utf8_validate(str)' failed - again?

    Hi guys, I have some small problem with creating JSON via jo, I saw this older issue, but I'm not sure what should I change in jo syntax. Can you help please?

    + jo -p -n -- -s id=1609290944590500000 name=Laputa pin=false 'categories=["Drama"]' type=movie seasonNumber= episodeNumber= 'meta[name]=Laputa' 'meta[description]=Sedmadvacetiletá Johanka tráví veškerý čas ve své kavárně Laputa. Má tolik možností, jak prožít svůj život. Přesto jí tato svoboda přináší pocit úzkosti a osamocení. Laputa je ostrov sám pro sebe. Johanka na něm trčí a neví, co se sebou dál...Kavárna Laputa je pro ostatní místem, kam přicházejí a zase odcházejí. Vydávají se žít své životy. Johančina sestra odjíždí s básníkem Mikim do Turecka. Felix, Johančina dávná láska se tu jen zastaví a zas odlétÀ na cesty. Merlot je štamgast, Johanku má rád a spává s ní. Jenže kromě ní taky s dalším milionem holek. Marnost na Johanku vykukuje z každého půllitru. Jako by se v její kavárně, kterou vybudovala, scházeli lidé, kteří umějí žít naplno. Každý s nějakým nápadem, potřebou nebo svým sobectvím. Johanka je všech a se všemi, a přece je sama a v nejistotě. Co si má počít v děsivě velkém prostoru dospělého života? Stačí jí její ostrov? Stačí si ona sama k pocitu úplnosti? Ke štěstí?' 'meta[adult]=false' 'meta[alternativeName]=[{"name":"Laputa"}]' 'meta[links]={"csfd":{"dbId":"film/388532","link":"https://www.csfd.cz/film/388532-laputa/prehled/"}}' 'meta[posterUrl]=1609290944590500000_poster.jpg' 'meta[backdropUrl]=1609290944590500000_preview.jpg' 'event[url]=../Laputa_cze_SD_ID_1609290944590500000.mpg' 'event[audioTracks]=[]' 'event[type]=video' 'event[hd]=true' 'event[subtitles]=' 'subscriptions=[{"code":"filmy","from":"2022-06-13T00:00:00+02:00","to":"2022-12-31T23:59:59+02:00"}]'
    jo: json.c:1209: emit_string: Assertion `utf8_validate(str)' failed.```
    opened by tom-i 9
  • jo 1.5 thinks it is jo 1.4

    jo 1.5 thinks it is jo 1.4

    For the jo 1.5 release, the project version number is still 1.4 in both the Autotools and Meson build systems.

    $ autoreconf --force --install
    $ ./configure 
    $ make
    $ ./jo -v
    jo 1.4
    $ meson build
    $ ninja -C build
    $ ./build/jo -v
    jo 1.4
    
    bug 
    opened by musicinmybrain 9
  • Replacing

    Replacing "null" with an actual null value works as documented

    I have a file called words.txt with

    abc
    null
    def
    

    And cat words.txt | jo -a -p creates

    [
       "abc",
       null,
       "def"
    ]
    

    The command jo -a -- abc null def produces the same output.

    A similar issue arises if the input data contains true, false, or something lke 1.23.

    The mission here is very simple: turn a lists of words into a JSON array. If jo messes with that list of words in any way, that is evil. The magic that is applied here should be opt-in or opt-out. But I currently see no switch to disable it and it's active by default. So this very simple goal (turning a list of words into a JSON array) cannot be achieved. That seems like a major oversight to me.

    Please enhance jo.

    opened by skoehler 9
  • Escaped double quotes don't work

    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.

    help wanted 
    opened by nikolay 9
  • Tests failing (Ubuntu 20.04)

    Tests failing (Ubuntu 20.04)

    I am running autoreconf -i, ./configure, make, and make check.

    The final lines of the configure output are

    configure: creating ./config.status
    config.status: creating Makefile
    config.status: creating tests/jo.07.sh
    config.status: executing depfiles commands
    
      Jo.............: version 1.6
      Prefix.........: /usr/local
      C compiler.....: gcc -g -O2
      Pandoc.........: NONE
      Bash completion: /usr/share/bash-completion/completions/jo.bash
    
      Now type 'make [<target>]'
        where the optional <target> is:
          all                - build all binaries
          check              - run the tests
          install            - install everything
    

    The make succeeds.

    [email protected]:~/C/jo$ make
      CC       jo.o
      CC       json.o
      CC       base64.o
      CCLD     jo
    

    A make check then explodes.

    [email protected]:~/C/jo$ make check
    make  check-TESTS
    make[1]: Entering directory '/home/kris/C/jo'
    make[2]: Entering directory '/home/kris/C/jo'
    ./build-aux/tap-driver.sh: line 16: $'\r': command not found
    ./build-aux/tap-driver.sh: line 21: $'\r': command not found
    ./build-aux/tap-driver.sh: line 25: $'\r': command not found
    ./build-aux/tap-driver.sh: line 27: $'\r': command not found
    : invalid optiondriver.sh: line 30: set: -
    set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
    ./build-aux/tap-driver.sh: line 31: $'\r': command not found
    ./build-aux/tap-driver.sh: line 33: $'\r': command not found
    ./build-aux/tap-driver.sh: line 34: syntax error near unexpected token `$'\r''
    '/build-aux/tap-driver.sh: line 34: `fatal ()
    make[2]: *** [Makefile:936: tests/jo.log] Error 2
    make[2]: Leaving directory '/home/kris/C/jo'
    make[1]: *** [Makefile:918: check-TESTS] Error 2
    make[1]: Leaving directory '/home/kris/C/jo'
    make: *** [Makefile:1120: check-am] Error 2
    

    There is no \r in tap-driver.sh, and the line numbers emitted are not really helpful.

    What's going on?

    opened by isotopp 8
  • enhancement: `k=@file`

    enhancement: `[email protected]`

    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 [email protected]
    {
       "authors": "Jan-Piet Mens <[email protected]>"
    }
    

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

    $ jo -p authors="$(cat AUTHORS)"
    
    enhancement 
    opened by bibby 8
  • build fail with 0.5 release on CentOS 6

    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)
    
    opened by z0mbix 8
  • Suberflous `\` if try to escape `}` in value

    Suberflous `\` if try to escape `}` in value

    Hello,

    I want to encode some JSON as string value. Therefore I used the trick to escape both the leading { and the trailing } with an \ like this:

    jo foo='\{"bla":"blub"\}'
    {"foo":"{\"bla\":\"blub\"\\}"
    
     jo foo='\{"bla":"blub"\}' -p | jq .foo
    "{\"bla\":\"blub\"\\}"
    

    As you can see, jo adds two \\ for the trailing }

    My expected result would have been:

     jo foo='\{"bla":"blub"\}' -p | jq .foo
    "{\"bla\":\"blub\"}"
    

    If only the leading { is escaped, jo detects the value as nested object:

    jo foo='\{"bla":"blub"}' -p
    {
       "foo": {
          "bla": "blub"
       }
    }
    

    Jo Version:

    jo -v
    jo 1.6
    
    opened by hikhvar 7
  • Request: Add ability to not interpret file substitution chars with arg instead of only escaping.

    Request: Add ability to not interpret file substitution chars with arg instead of only escaping.

    If some values are coming from user input, it is possible (however unlikely) that someone could input a literal string that start with @, %, or :. If this were to happen, jo would try to interpret those values as files to read and would fail to create JSON if the file doesn't exist (or create unintended JSON if the file does exist).

    Currently, the only way to avoid this is to manually escape those characters with a \. But, if these values are coming from user input having to do any pre-processing and escaping on those values before passing them to jo kind defeats some of the great value of jo being able to make valid JSON without needing to manually escape things like double quotes within values.

    To avoid this possible issue when values should be treated literally no matter what without anything needing to be manually escaped within the value, I'm thinking there could be a new coercion-style argument and/or a global arg to not interpret those special jo characters. I could see value in both a global option and a per value option depending on the scenario. I'm thinking something like -l (for "literal") could be good candidates for this kind of option.

    Hopefully, this could be combined with existing coercion args so that something like jo -- -ls "key=${user_input_value}" could be done to always interpret user_input_value as a "literal string" without needing to escape any special characters in the string.

    Thanks so much for considering this as well as for the amazingly useful jo!

    enhancement question 
    opened by PicoMitchell 18
Releases(1.6)
A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON

JSONCONS jsoncons is a C++, header-only library for constructing JSON and JSON-like data formats such as CBOR. For each supported data format, it enab

Daniel Parker 521 Sep 14, 2022
QJson is a qt-based library that maps JSON data to QVariant objects.

QJson JSON (JavaScript Object Notation) is a lightweight data-interchange format. It can represents integer, real number, string, an ordered sequence

Flavio Castelli 269 Sep 17, 2022
json-cpp is a C++11 JSON serialization library.

JSON parser and generator for C++ Version 0.1 alpha json-cpp is a C++11 JSON serialization library. Example #include <json-cpp.hpp> struct Foo {

Anatoly Scheglov 4 Dec 31, 2019
This is a JSON C++ library. It can write and read JSON files with ease and speed.

Json Box JSON (JavaScript Object Notation) is a lightweight data-interchange format. Json Box is a C++ library used to read and write JSON with ease a

Anhero inc. 108 Aug 26, 2022
A convenience C++ wrapper library for JSON-Glib providing friendly syntactic sugar for parsing JSON

This library is a wrapper for the json-glib library that aims to provide the user with a trivial alternative API to the API provided by the base json-

Rob J Meijer 16 May 10, 2022
json-build is a zero-allocation JSON serializer compatible with C89

json-build is a zero-allocation JSON serializer compatible with C89. It is inspired by jsmn, a minimalistic JSON tokenizer.

Lucas Müller 28 Sep 14, 2022
A small header-only json library in C.

xjson A small header-only json library for C. The "unique" feature is that it allows use of the same code to serialize as well as deserialize, greatly

Stefan Bachmann 23 Jul 19, 2022
A small header-only library for converting data between json representation and c++ structs

Table of Contents Table of Contents What Is json_dto? What's new? v.0.3.0 v.0.2.14 v.0.2.13 v.0.2.12 v.0.2.11 v.0.2.10 v.0.2.9 v.0.2.8 v.0.2.7 v.0.2.6

Stiffstream 99 Sep 22, 2022
Ultralightweight JSON parser in ANSI C

cJSON Ultralightweight JSON parser in ANSI C. Table of contents License Usage Welcome to cJSON Building Copying the source CMake Makefile Vcpkg Includ

Dave Gamble 7.9k Sep 17, 2022
JSON parser and generator for C/C++ with scanf/printf like interface. Targeting embedded systems.

JSON parser and emitter for C/C++ Features ISO C and ISO C++ compliant portable code Very small footprint No dependencies json_scanf() scans a string

Cesanta Software 619 Sep 13, 2022
C library for encoding, decoding and manipulating JSON data

Jansson README Jansson is a C library for encoding, decoding and manipulating JSON data. Its main features and design principles are: Simple and intui

Petri Lehtinen 2.7k Sep 18, 2022
JSON & BSON parser/writer

jbson is a library for building & iterating BSON data, and JSON documents in C++14. \tableofcontents Features # {#features} Header only. Boost license

Chris Manning 40 Sep 14, 2022
A very sane (header only) C++14 JSON library

JeayeSON - a very sane C++14 JSON library JeayeSON was designed out of frustration that there aren't many template-based approaches to handling JSON i

Jeaye Wilkerson 128 Jun 7, 2022
Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket

JSMN jsmn (pronounced like 'jasmine') is a minimalistic JSON parser in C. It can be easily integrated into resource-limited or embedded projects. You

Serge Zaitsev 3k Sep 22, 2022
JSON for Modern C++

Design goals Sponsors Integration CMake Package Managers Pkg-config Examples JSON as first-class data type Serialization / Deserialization STL-like ac

Niels Lohmann 31.8k Sep 22, 2022
A JSON parser in C++

JSON++ Introduction JSON++ is a light-weight JSON parser, writer and reader written in C++. JSON++ can also convert JSON documents into lossless XML d

Hong Jiang 488 Sep 13, 2022
🗄️ single header json parser for C and C++

??️ json.h A simple single header solution to parsing JSON in C and C++. JSON is parsed into a read-only, single allocation buffer. The current suppor

Neil Henning 511 Sep 9, 2022
A C++ library for interacting with JSON.

JsonCpp JSON is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value p

null 6.7k Sep 25, 2022
Very low footprint JSON parser written in portable ANSI C

Very low footprint JSON parser written in portable ANSI C. BSD licensed with no dependencies (i.e. just drop the C file into your project) Never recur

James McLaughlin 1.2k Sep 22, 2022