From JSON Text.vim does not return an error or flag when missing objects

Issue #108 new
Simon Fransen created an issue

From JSON Text.vim does not throw an error or flag to indicate that an element in the data type input is missing from the input JSON text.

I currently have an application where we would like to flag if any values are missing and generate an invalid JSON file message.

The below simplified example has a typo in the “string” object name.

The above typo is handled very gracefully and silently substitutes the default value into the data output. I think this is great functionality for the majority of applications, but not for ones where the validation of the input text is very important.

I would like it if the function throws an error in this scenario, but understand that this would break a lot of applications that rely on the clean substitution of default values (including my own applications).

Is there scope to add an optional argument for whether the function produces an error?

Could we add a “found all?” result to the output terminal? Maybe an array of paths that weren’t found?

Is there a function or simple process that can compare the object names in JSON text with the element names in a cluster, whilst ignoring the values (except for objects/clusters as values)? I could only find solutions that would involve re-writing a lot of the recursive steps and data type checking.

Any help would be appreciated. Thank you to everyone working on this package.

Regards,

Simon Fransen

Comments (5)

  1. James Powell repo owner

    Note: a workaround you can do today is to use the “Flatten JSON Object to JSONpath Array” vi. Use it on your JSON and the JSON-converted Cluster and check that all paths in one are present in the other.

  2. Simon Fransen reporter

    Thanks James,

    This workaround helps a lot to do validation on the parsed json file.

    Playing around with this, I noticed typos in arrays of clusters aren’t handled by the work-around. Additionally, it doesn’t look like defaults are able to be set within arrays of clusters.

    In the below case, the misspelt string is not picked up in the path string array. Additionally, the misspelt string is treated as a null blank string rather than the “default” string.

    My current application parses arrays of json strings and then parses each string element by element, so your mentioned work around will work for this case.

    Are there any plans to implement something like jsonschema?

  3. Log in to comment