Skip to content

Repository files navigation

@jsonic/directive — directive syntax for Jsonic

Adds directive syntax to the Jsonic JSON parser. A directive is a token sequence (e.g. @name, add<1,2>) that triggers custom parsing behaviour. TypeScript and Go ports share the same API shape and test specs.

npm versionbuild

Documentation

This project's documentation follows the Diátaxis framework. Each section has one job — pick the one that matches what you're trying to do.

If you want to…Read
Build your first directive step-by-stepTutorial
Solve a specific problemHow-to guides
Look up an option, type, or defaultReference
Understand how the plugin works internallyExplanation

Quickstart

TypeScript

import{Jsonic}from'jsonic'import{Directive}from'@jsonic/directive'constj=Jsonic.make().use(Directive,{name: 'upper',open: '@',action: (rule)=>(rule.node=String(rule.child.node).toUpperCase()),})j('[@a, @b, 1]')// → ['A', 'B', 1]

Go

import (
jsonic "github.com/jsonicjs/jsonic/go"
directive "github.com/jsonicjs/directive/go"
)
j:=jsonic.Make()
directive.Apply(j, directive.DirectiveOptions{
Name: "upper",
Open: "@",
Action: func(r*jsonic.Rule, _*jsonic.Context) {
r.Node=strings.ToUpper(fmt.Sprintf("%v", r.Child.Node))
},
})
j.Parse("[@a, @b, 1]") // → []any{"A", "B", float64(1)}

License

MIT — see LICENSE.

About

Add directives to Jsonic

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages