The simple JSON parser with validation by condition

omg.jsonParser

Go Go Reference Coverage Status Go Report Card

omg.jsonParser is a simple JSON parser with a simple condition validation. It's a wrapper on standard go JSON lib. With it help you can add the validation condition via golang structure fields tags.

Example

package main

import (
	"fmt"

	"github.com/dedalqq/omg.jsonparser"
)

func main() {
	jsonData := `{"name": ""}`

	st := struct {
		Name string `json:"name,notEmpty"` // added notEmpty for enable validation for it field
	}{}

	err := jsonparser.Unmarshal([]byte(jsonData), &st)
	if err != nil {
		fmt.Println(err.Error()) // print: value [name] must be not empty
	}
}

Tag struct

json:"[name][,option]..."

Tag examples

Here are some the tag examples:

package main

type data struct {
    F1 string   `json:"f1,notEmpty"`          // the field must be not empty but can be "null" or may not exist
    F2 string   `json:"f2,notEmpty,required"` // the field is required and must be not empty but may be the "null" value
    F3 string   `json:"f3,notEmpty,notNull"`  // the field must be not empty and not "null" but may not exist
    F4 []string `json:"f4,notNull,min:3"`     // the field must be not "null" and contains 3 or more items but may not exist
}

Available tags options

Name Types Description
required any The field must be exist with any value or null
notEmpty any The field can be not exist but if exist value must be not zero value but can be null
notEmpty slice The field must have one element or more but may be null or not exist
notNull any The field should not be null, but may not exist
uniq []string The strings slice must contains only unique strings
min:n slice The slice must have n items or more
max:n slice The slice must have n items or less
min:n string The string must have n runes or more
max:n string The string must have n runes or less
min:n int/uint The value must be equals n or more
max:n int/uint The value must be equals n or less
Owner
Timofey Kovalev
¯ \ _ (ツ) _ / ¯
Timofey Kovalev
Similar Resources

Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Jan 6, 2023

Package json implements encoding and decoding of JSON as defined in RFC 7159

Package json implements encoding and decoding of JSON as defined in RFC 7159. The mapping between JSON and Go values is described in the documentation for the Marshal and Unmarshal functions

Jun 26, 2022

Json-go - CLI to convert JSON to go and vice versa

Json-go - CLI to convert JSON to go and vice versa

Json To Go Struct CLI Install Go version 1.17 go install github.com/samit22/js

Jul 29, 2022

Simple Email Parser

mp - mail parser mp is a simple cli email parser. It currently takes stdin and outputs JSON. Example: cat fixtures/test.eml | mp { "Text": "Hello w

Sep 26, 2022

Go-json5 - A parser that supports a subset of the JSON5 specification

barney.ci/go-json5 This library implements a parser that supports a subset of th

Oct 10, 2022

A simple Go package to Query over JSON/YAML/XML/CSV Data

A simple Go package to Query over JSON/YAML/XML/CSV Data

A simple Go package to Query over JSON Data. It provides simple, elegant and fast ODM like API to access, query JSON document Installation Install the

Dec 27, 2022

Simple json based db, if you call db xd.

Golang-json-db Simple json based db, if you call db xd. Basics //First of all you have to config main json file then config backup json file. Backup i

Sep 27, 2021

Simple user currency module that uses JSON.

UserCurrency Simple user currency module that uses JSON. Install go get github.com/NeutronX-dev/UserCurrency Functions func UserCurrency.Read(path_to

Nov 23, 2021

A Simple JSON Description of Telegraph API

A Simple JSON Description of Telegraph API

telegraph-api-spec Introduction This golang program generates a JSON description of methods, types and docstrings of the Telegraph API. Features Easy

Nov 21, 2022
A JSON stream parser for Go

pjson A JSON stream parser for Go Example The example below prints all string values from a JSON document. package

Oct 3, 2022
One of the fastest alternative JSON parser for Go that does not require schema

Alternative JSON parser for Go (10x times faster standard library) It does not require you to know the structure of the payload (eg. create structs),

Jan 2, 2023
A fast json parser for go

rjson rjson is a json parser that relies on Ragel-generated state machines for most parsing. rjson's api is minimal and focussed on efficient parsing.

Sep 26, 2022
Slow and unreliable JSON parser generator (in progress)

VivaceJSON Fast and reliable JSON parser generator Todo List parse fields parse types generate struct generate (keypath+key) to struct Value Mapping F

Nov 26, 2022
JSON:API compatible query string parser

QParser The package helps to parse part of the URL path and its parameters string to a handy structure. The structure format is compatible with the JS

Dec 21, 2021
Easy JSON parser for Go. No custom structs, no code generation, no reflection

Easy JSON parser for Go. No custom structs, no code generation, no reflection

Dec 28, 2022
A JSON parser/generator for Go

FASTJSON fastjson是java版本的fastjson库的api做一个翻译,方便习惯java的人操作json数据 主要适用场景:层级和字段都不能确定的json 这个库并不实现高性能json解析,依赖标准库json 这个库并没有100%实现java版的api 安装 go get -u gi

Dec 29, 2021
JSON Spanner - A Go package that provides a fast and simple way to filter or transform a json document

JSON SPANNER JSON Spanner is a Go package that provides a fast and simple way to

Sep 14, 2022
A Small tool for SDWAN performance test and policy validation

sdwan-perf Sdwan-perf is based on golang and could support almost platform for performance and policy validation. SDWAN Performance Test Report +--

Sep 3, 2022
JSON diff library for Go based on RFC6902 (JSON Patch)

jsondiff jsondiff is a Go package for computing the diff between two JSON documents as a series of RFC6902 (JSON Patch) operations, which is particula

Dec 4, 2022