ianka / xjson.tcl Goto Github PK
View Code? Open in Web Editor NEWA Tcl library that validates, collects, composes JSON data against supplied schemas and to/from Tcl data.
License: Other
A Tcl library that validates, collects, composes JSON data against supplied schemas and to/from Tcl data.
License: Other
Thank you sir for u interesting library. I found it very useful.
My use case:
I have hi compound json with very big level nestng. I need to replace some long string value inside this json to another long string value.
I am doing xjson::decode, getting long nested dictionary.And then in my vim editor i copy this dictionary to another line, and found in this line by search place where that string to replace is.
And then i am making small change in that string, just to create patch like it described in you docks.
package require xjson
set old_json $SOME_LONG_DICT
set new_json $SOME_LONG_NEW_DICT
set diff [xjson::diff $new_json $old_json]
And then i am getting patch that allow me easily replace string in old big json with 'rpatch replace' without addressing it directly like in php for example.
PERFECT!!
But problem is that i can replace only that exactly matched string in patch and i am want
a GLOB MATCHED string.
So i took source code, file patch.tcl, found rpatch function and replace check in line 223:
if {$patchParam2 ne $decodedJson} to if {![string match $patchParam2 $decodedJson]}
And then i replace target string in patch to glob "*small_string*".
And IT WORKED!!
It allow me to obtain all my json in database without creating multiple patches.
And it PASSES ALL TESTS!!
Mb u should consider feature like this in u excellent library??
Thank you.
I have the following Tcl fragment
package require xjson
namespace path ::xjson
makeCollectorClass Collector
Collector typeCollector {
object {Kind string Name string}
}
Collector constantCollector typeCollector typeCollector {
object {
Name string
Type {nest typeCollector}
ValueType string
Value {anyof {string number}}
Attrs {array string}
}
}
Collector collector constantCollector constantCollector {
object {
Constants {array {nest constantCollector}}
}
}
I'm parsing the following sample data with it.
set json {
{
"Constants":[
{
"Name":"WAIT_OBJECT_0"
,"Type":{"Kind":"Native","Name":"UInt32"}
,"ValueType":"UInt32"
,"Value":0
,"Attrs":[]
}
,{
"Name":"WAIT_ABANDONED"
,"Type":{"Kind":"Native","Name":"UInt32"}
,"ValueType":"UInt32"
,"Value":128
,"Attrs":[]
}
]
}
}
This works fine. However, I don't really need all fields such as ValueType so I thought I would just discard them. However, if I change the schema to
Collector constantCollector typeCollector typeCollector {
object {
Name string
Type {nest typeCollector}
ValueType discard
Value {anyof {string number}}
Attrs {array string}
}
}
expecting the ValueType field to be thrown away, I get the following error
decoded JSON data "{
"Name": "WAIT_OBJECT_0",
"Type": {
"Kind": "Native",
"Name": "UInt32"
},
"ValueType": "UInt32",
"Value": 0,
"Attrs": []
}" does not match schema {object {
"Name" string
"Type" {nest "typeCollector"}
"ValueType" discard
"Value" {anyof {string number}}
"Attrs" {array string}
}} at /object:Constants/array#0/nest:constantCollector/
Object field "ValueType" is missing.
Clearly I'm either misunderstanding the purpose of the discard
method or using it wrong. So how do I get the effect I want (essentially ignoring that field) ? I could of course discard the field at the Tcl level but in other cases the discarded field schema is quite complex so I would prefer to not write schemas for them.
I just started using this package seriously to generate Tcl bindings for the Win32 API. A request I'd like to make (had also made it on the wiki) is to move to TclOO from itcl as it does not currently work with Tcl 9 and I'm doubtful about its long term support and time frame.
Am really liking this package for the purpose I'm using it for. Nicely done!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.