Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support so subsitutions can use JsonPath #112

Merged
merged 10 commits into from
Sep 17, 2019

Conversation

BlythMeister
Copy link
Member

Use the standard subsitution files to update JSON rather than XML.

This will only support ChangeValue & ReplacementContent (for now)

Adding new and add child content are out of scope for now.

<Root xmlns="http://15below.com/Substitutions.xsd">
<Namespaces />
<Files>
<File Filename="TestUpdateFiles\TestJson01.json" FileType="JSON">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make the FileType parameter optional - i.e. if the file extension ends with .json then it's implied anyway?

<Changes>
<Change type="ChangeValue" jsonPath="$.Data" value="NewData" />
<Change type="ChangeValue" jsonPath="$.SubTrees.DataPoint.Value" value="Bill" />
<Change type="ReplacementContent" jsonPath="$.Collection">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything fundamentally different between "ChangeValue" and "ReplacementContent"?
Apart from the fact that one allows you to enter a CDATA section? Could this potentially be merged into one operation? E.g. using either a value attribute or a node?

@BlythMeister
Copy link
Member Author

@richard-green changes made as requested

Copy link
Contributor

@richard-green richard-green left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor stuff, feel free to merge when ready

<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll</HintPath>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a paket reference?

{
Logging.Log($"Updating JsonPath {sub.Path}");

var xPathMatches = baseJson.SelectTokens(sub.Path.RenderTemplate(tagValues)).ToList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> pathMatches


if (!sub.PathMatchAll && xPathMatches.Count > 1)
{
throw new ApplicationException($"JsonPath select of {sub.Path} returned multiple matches. If the intention was to update all matches, use the attribute matchAll=\"true\" on the XPath or Change node.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XPath => jsonPath?

@BlythMeister BlythMeister merged commit d00fc8f into 15below:develop Sep 17, 2019
@BlythMeister BlythMeister deleted the jsonpath branch September 17, 2019 07:42
@BlythMeister BlythMeister mentioned this pull request Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants