Git Product home page Git Product logo

xjson.tcl's People

Contributors

ianka avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xjson.tcl's Issues

xjson::rpatch replace and other same actions with glob match

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.

Question about the discard method.

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.

RFE - Tcl 9 support

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!

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.